Skip to content

Commit 4a7aae5

Browse files
authored
Detect if afunix.h exists (#2145)
Signed-off-by: Piotr Stankiewicz <[email protected]>
1 parent fd324e1 commit 4a7aae5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

httplib.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,13 @@ using ssize_t = long;
192192
#include <winsock2.h>
193193
#include <ws2tcpip.h>
194194

195+
#if defined(__has_include)
196+
#if __has_include(<afunix.h>)
195197
// afunix.h uses types declared in winsock2.h, so has to be included after it.
196198
#include <afunix.h>
199+
#define CPPHTTPLIB_HAVE_AFUNIX_H 1
200+
#endif
201+
#endif
197202

198203
#ifndef WSA_FLAG_NO_HANDLE_INHERIT
199204
#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
@@ -3551,6 +3556,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
35513556
hints.ai_flags = socket_flags;
35523557
}
35533558

3559+
#if !defined(_WIN32) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
35543560
if (hints.ai_family == AF_UNIX) {
35553561
const auto addrlen = host.length();
35563562
if (addrlen > sizeof(sockaddr_un::sun_path)) { return INVALID_SOCKET; }
@@ -3595,6 +3601,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
35953601
}
35963602
return sock;
35973603
}
3604+
#endif
35983605

35993606
auto service = std::to_string(port);
36003607

0 commit comments

Comments
 (0)