diff --git a/compile_windows.sh b/compile_windows.sh old mode 100644 new mode 100755 index f532220..c42affb --- a/compile_windows.sh +++ b/compile_windows.sh @@ -139,7 +139,7 @@ ccache g++ -Wall \ sfw/render_objects/camera_2d.o sfw/render_objects/mesh_instance_2d.o \ sfw/render_objects/text_2d.o \ sfw/game_scene.o sfw/main.o \ - -lgdi32 -lShlwapi \ + -lgdi32 -lShlwapi -lws2_32 \ -o game #export args="-lm -ldl -lpthread -lX11 -w -Iengine/ $args" \ No newline at end of file diff --git a/sfw/core/inet_address.cpp b/sfw/core/inet_address.cpp index 0081173..c870af1 100644 --- a/sfw/core/inet_address.cpp +++ b/sfw/core/inet_address.cpp @@ -26,7 +26,18 @@ extern "C" { WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf); -WINSOCK_API_LINKAGE PCSTR WSAAPI inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize); + +#ifdef __MINGW64_VERSION_MAJOR +#if __MINGW64_VERSION_MAJOR >= 7 +WINSOCK_API_LINKAGE PCSTR WSAAPI inet_ntop(INT Family, const VOID * pAddr, PSTR pStringBuf, size_t StringBufSize); +#else +WINSOCK_API_LINKAGE PCSTR WSAAPI inet_ntop(INT Family, VOID * pAddr, PSTR pStringBuf, size_t StringBufSize); +#endif + +#else +WINSOCK_API_LINKAGE PCSTR WSAAPI inet_ntop(INT Family, VOID * pAddr, PSTR pStringBuf, size_t StringBufSize); +#endif + } #else // Windows... @@ -48,6 +59,10 @@ struct in6__addruint { #include // memset #endif +#ifdef _MSC_VER +#pragma comment(lib, "ws2_32") +#endif + // INADDR_ANY use (type)value casting. static const in_addr_t kInaddrAny = INADDR_ANY; static const in_addr_t kInaddrLoopback = INADDR_ANY; diff --git a/sfw/core/socket.cpp b/sfw/core/socket.cpp index b9df542..a71e638 100644 --- a/sfw/core/socket.cpp +++ b/sfw/core/socket.cpp @@ -197,7 +197,8 @@ int Socket::accept(Socket *sock) { sock->_socket = connfd; sock->_address.set_sock_addr_inet6(addr6); #ifndef __linux__ - sock->set_non_block_and_close_on_exit(); + sock->set_non_block(); + sock->set_close_on_exit(); #endif } @@ -291,7 +292,7 @@ void Socket::set_keep_alive(bool on) { } struct sockaddr_in6 Socket::get_local_addr(int *r_err) { - struct sockaddr_in6 localaddr; + struct sockaddr_in6 localaddr = { 0 }; ERR_FAIL_COND_V(_socket == 0, localaddr); @@ -308,7 +309,8 @@ struct sockaddr_in6 Socket::get_local_addr(int *r_err) { } struct sockaddr_in6 Socket::get_peer_addr(int *r_err) { - struct sockaddr_in6 peeraddr; + struct sockaddr_in6 peeraddr = { 0 }; + ERR_FAIL_COND_V(_socket == 0, peeraddr); memset(&peeraddr, 0, sizeof(peeraddr));