Skip to content

Commit 7e0a76a

Browse files
committed
[build] Fix MinGW missing GetAddrInfoExCancel definition
MinGW does not define GetAddrInfoExCancel in its wstcpi whatever header, so to get around this we can just load it with GetProcAddress et al. Signed-off-by: crueter <[email protected]>
1 parent db561f5 commit 7e0a76a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

httplib.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@
203203
#error Sorry, Visual Studio versions prior to 2015 are not supported
204204
#endif
205205

206-
#pragma comment(lib, "ws2_32.lib")
207-
208206
using ssize_t = __int64;
209207
#endif // _MSC_VER
210208

209+
#if defined(_MSC_VER) || defined(__MINGW32__)
210+
#pragma comment(lib, "ws2_32.lib")
211+
#endif
212+
211213
#ifndef S_ISREG
212214
#define S_ISREG(m) (((m) & S_IFREG) == S_IFREG)
213215
#endif // S_ISREG
@@ -3557,7 +3559,15 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
35573559
auto wait_result =
35583560
::WaitForSingleObject(event, static_cast<DWORD>(timeout_sec * 1000));
35593561
if (wait_result == WAIT_TIMEOUT) {
3562+
#ifdef __MINGW32__
3563+
typedef INT (WSAAPI *PFN_GETADDRINFOEXCANCEL)(HANDLE *CancelHandle);
3564+
auto wsdll = LoadLibraryW((wchar_t*) "ws2_32.lib");
3565+
PFN_GETADDRINFOEXCANCEL GetAddrInfoExCancel = (PFN_GETADDRINFOEXCANCEL) GetProcAddress(wsdll, "GetAddrInfoExCancel");
3566+
3567+
if (cancel_handle) { GetAddrInfoExCancel(&cancel_handle); }
3568+
#else
35603569
if (cancel_handle) { ::GetAddrInfoExCancel(&cancel_handle); }
3570+
#endif
35613571
::CloseHandle(event);
35623572
return EAI_AGAIN;
35633573
}

0 commit comments

Comments
 (0)