1
0
mirror of synced 2025-04-21 22:25:55 +03:00

Merge pull request #292 from Bendr0id/fix_socket_create_on_older_windows_systems

Adds workaround for socket creation on older Windows variants
This commit is contained in:
yhirose 2019-12-18 07:09:48 -05:00 committed by GitHub
commit 80202c9f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1302,6 +1302,22 @@ socket_t create_socket(const char *host, int port, Fn fn,
#ifdef _WIN32 #ifdef _WIN32
auto sock = WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, auto sock = WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol,
nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT); nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT);
/**
* Since the WSA_FLAG_NO_HANDLE_INHERIT is only supported on Windows 7 SP1 and above
* the socket creation fails on older Windows Systems.
*
* Let's try to create a socket the old way in this case.
*
* Reference:
* https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketa
*
* WSA_FLAG_NO_HANDLE_INHERIT:
* This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
*
*/
if (sock == INVALID_SOCKET) {
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
}
#else #else
auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
#endif #endif