Util: Use closesocket on Windows

This commit is contained in:
Jeffrey Pfau 2016-03-05 11:33:36 -08:00
parent 82720ca26e
commit b8387abf8d
2 changed files with 11 additions and 6 deletions

View File

@ -14,6 +14,7 @@ Bugfixes:
- GBA Serialize: Fix memory corruption bug in GBAExtdataSerialize
- GBA Serialize: Fix loading savegames from savestates
- All: Fix several file handle leaks
- Util: Use closesocket on Windows
Misc:
- GBA: Slightly optimize GBAProcessEvents
- Qt: Add preset for DualShock 4

View File

@ -83,6 +83,14 @@ static inline ssize_t SocketRecv(Socket socket, void* buffer, size_t size) {
#endif
}
static inline int SocketClose(Socket socket) {
#ifdef _WIN32
return closesocket(socket) == 0;
#else
return close(socket) >= 0;
#endif
}
static inline Socket SocketOpenTCP(int port, const struct Address* bindAddress) {
Socket sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (SOCKET_FAILED(sock)) {
@ -112,7 +120,7 @@ static inline Socket SocketOpenTCP(int port, const struct Address* bindAddress)
err = bind(sock, (const struct sockaddr*) &bindInfo, sizeof(bindInfo));
}
if (err) {
close(sock);
SocketClose(sock);
return INVALID_SOCKET;
}
return sock;
@ -148,7 +156,7 @@ static inline Socket SocketConnectTCP(int port, const struct Address* destinatio
}
if (err) {
close(sock);
SocketClose(sock);
return INVALID_SOCKET;
}
return sock;
@ -179,10 +187,6 @@ static inline Socket SocketAccept(Socket socket, struct Address* address) {
}
}
static inline int SocketClose(Socket socket) {
return close(socket) >= 0;
}
static inline int SocketSetBlocking(Socket socket, bool blocking) {
#ifdef _WIN32
u_long unblocking = !blocking;