all repos — mgba @ c73ea2e5955514535d1a56794c727e8049ef97e1

mGBA Game Boy Advance Emulator

Util: Fix sockets on Windows
Jeffrey Pfau jeffrey@endrift.com
Mon, 23 Feb 2015 23:27:28 -0800
commit

c73ea2e5955514535d1a56794c727e8049ef97e1

parent

1ff9968a906dd51077f6eabea1fcdfdcd8d596ec

3 files changed, 26 insertions(+), 6 deletions(-)

jump to
M CHANGESCHANGES

@@ -45,6 +45,7 @@ - Qt: Fix crash starting a GDB stub if a game isn't loaded

- 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
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -24,6 +24,8 @@ #ifdef BUILD_SDL

SDL_Init(SDL_INIT_NOPARACHUTE); #endif + SocketSubsystemInit(); + QApplication::setApplicationName(PROJECT_NAME); QApplication::setApplicationVersion(PROJECT_VERSION);
M src/util/socket.hsrc/util/socket.h

@@ -42,18 +42,35 @@ uint8_t ipv6[16];

}; }; -static inline void SocketSubsystemInitialize() { +static inline void SocketSubsystemInit() { +#ifdef _WIN32 + 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 - WSAStartup(MAKEWORD(2, 2), 0); + 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 @@

} if (err) { close(sock); - return -1; + return INVALID_SOCKET; } return sock; }

@@ -123,7 +140,7 @@ }

if (err) { close(sock); - return -1; + return INVALID_SOCKET; } return sock; }