all repos — mgba @ b8387abf8d403eaaaf33e8f5df99a2fe78e8c643

mGBA Game Boy Advance Emulator

Util: Use closesocket on Windows
Jeffrey Pfau jeffrey@endrift.com
Sat, 05 Mar 2016 11:33:36 -0800
commit

b8387abf8d403eaaaf33e8f5df99a2fe78e8c643

parent

82720ca26eaac3fb42e500924cea265d2bbe4301

2 files changed, 11 insertions(+), 6 deletions(-)

jump to
M CHANGESCHANGES

@@ -14,6 +14,7 @@ - Qt: Initialize m_useBios

- 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
M src/util/socket.hsrc/util/socket.h

@@ -83,6 +83,14 @@ return read(socket, buffer, 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 @@ memcpy(bindInfo.sin6_addr.s6_addr, bindAddress->ipv6, sizeof(bindInfo.sin6_addr.s6_addr));

err = bind(sock, (const struct sockaddr*) &bindInfo, sizeof(bindInfo)); } if (err) { - close(sock); + SocketClose(sock); return INVALID_SOCKET; } return sock;

@@ -148,7 +156,7 @@ err = connect(sock, (const struct sockaddr*) &bindInfo, sizeof(bindInfo));

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

@@ -177,10 +185,6 @@ memcpy(addrInfo.sin6_addr.s6_addr, address->ipv6, sizeof(addrInfo.sin6_addr.s6_addr));

socklen_t len = sizeof(addrInfo); return accept(socket, (struct sockaddr*) &addrInfo, &len); } -} - -static inline int SocketClose(Socket socket) { - return close(socket) >= 0; } static inline int SocketSetBlocking(Socket socket, bool blocking) {