aboutsummaryrefslogtreecommitdiff
path: root/.patch/httplib/0001-mingw.patch
blob: da9a9e74bd2ef29bb77e2b695f9d6e7e7ec97a71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 436fc1978c78edd085d99b33275b24be0ac96aa0 Mon Sep 17 00:00:00 2001
From: crueter <crueter@eden-emu.dev>
Date: Sun, 1 Feb 2026 16:21:10 -0500
Subject: [PATCH] Fix build on MinGW

MinGW doesn't define GetAddrInfoExCancel.

Signed-off-by: crueter <crueter@eden-emu.dev>
---
 httplib.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/httplib.h b/httplib.h
index ec8d2a2..5f9a510 100644
--- a/httplib.h
+++ b/httplib.h
@@ -203,14 +203,17 @@
 #error Sorry, Visual Studio versions prior to 2015 are not supported
 #endif
 
-#pragma comment(lib, "ws2_32.lib")
-
 #ifndef _SSIZE_T_DEFINED
 using ssize_t = __int64;
 #define _SSIZE_T_DEFINED
 #endif
 #endif // _MSC_VER
 
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#pragma comment(lib, "ws2_32.lib")
+#endif
+
+
 #ifndef S_ISREG
 #define S_ISREG(m) (((m) & S_IFREG) == S_IFREG)
 #endif // S_ISREG
@@ -4528,7 +4531,17 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
     auto wait_result =
         ::WaitForSingleObject(event, static_cast<DWORD>(timeout_sec * 1000));
     if (wait_result == WAIT_TIMEOUT) {
+#ifdef __MINGW32__
+      typedef INT(WSAAPI * PFN_GETADDRINFOEXCANCEL)(HANDLE * CancelHandle);
+      auto wsdll = LoadLibraryW((wchar_t *)"ws2_32.lib");
+      PFN_GETADDRINFOEXCANCEL GetAddrInfoExCancel =
+          (PFN_GETADDRINFOEXCANCEL)GetProcAddress(wsdll, "GetAddrInfoExCancel");
+
+      if (cancel_handle) { GetAddrInfoExCancel(&cancel_handle); }
+#else
       if (cancel_handle) { ::GetAddrInfoExCancel(&cancel_handle); }
+#endif
+
       ::CloseHandle(event);
       return EAI_AGAIN;
     }
@@ -13952,3 +13965,4 @@ inline SSL_CTX *Client::ssl_context() const {
 } // namespace httplib
 
 #endif // CPPHTTPLIB_HTTPLIB_H
+
-- 
2.51.2