Util: Fix sockets on Windows

This commit is contained in:
Jeffrey Pfau 2015-02-23 23:27:28 -08:00
parent 1ff9968a90
commit c73ea2e595
3 changed files with 26 additions and 6 deletions

View File

@ -45,6 +45,7 @@ Bugfixes:
- Qt: Fix crash when adjusting settings after closing a game
- Qt: Fix crash when starting GDB stub after closing a game
- Qt: Fix patch loading while a game is running
- Util: Fix sockets on Windows
Misc:
- GBA Audio: Change internal audio sample buffer from 32-bit to 16-bit samples
- GBA Memory: Simplify memory API and use fixed bus width

View File

@ -24,6 +24,8 @@ GBAApp::GBAApp(int& argc, char* argv[])
SDL_Init(SDL_INIT_NOPARACHUTE);
#endif
SocketSubsystemInit();
QApplication::setApplicationName(PROJECT_NAME);
QApplication::setApplicationVersion(PROJECT_VERSION);

View File

@ -42,18 +42,35 @@ struct Address {
};
};
static inline void SocketSubsystemInitialize() {
static inline void SocketSubsystemInit() {
#ifdef _WIN32
WSAStartup(MAKEWORD(2, 2), 0);
WSADATA data;
WSAStartup(MAKEWORD(2, 2), &data);
#endif
}
static inline int SocketError() {
#ifdef _WIN32
return WSAGetLastError();
#else
return errno;
#endif
}
static inline bool SocketWouldBlock() {
#ifdef _WIN32
return SocketError() == WSAEWOULDBLOCK;
#else
return SocketError() == EWOULDBLOCK || SocketError() == EAGAIN;
#endif
}
static inline ssize_t SocketSend(Socket socket, const void* buffer, size_t size) {
return write(socket, buffer, size);
return send(socket, buffer, size, 0);
}
static inline ssize_t SocketRecv(Socket socket, void* buffer, size_t size) {
return read(socket, buffer, size);
return recv(socket, buffer, size, 0);
}
static inline Socket SocketOpenTCP(int port, const struct Address* bindAddress) {
@ -87,7 +104,7 @@ static inline Socket SocketOpenTCP(int port, const struct Address* bindAddress)
}
if (err) {
close(sock);
return -1;
return INVALID_SOCKET;
}
return sock;
}
@ -123,7 +140,7 @@ static inline Socket SocketConnectTCP(int port, const struct Address* destinatio
if (err) {
close(sock);
return -1;
return INVALID_SOCKET;
}
return sock;
}