From 4a7aae54690c80e7d49398964ba9e1bae1dfca79 Mon Sep 17 00:00:00 2001 From: Piotr Date: Sat, 24 May 2025 05:14:48 +0200 Subject: [PATCH] Detect if afunix.h exists (#2145) Signed-off-by: Piotr Stankiewicz --- httplib.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/httplib.h b/httplib.h index ae4507d..e1eb470 100644 --- a/httplib.h +++ b/httplib.h @@ -192,8 +192,13 @@ using ssize_t = long; #include #include +#if defined(__has_include) +#if __has_include() // afunix.h uses types declared in winsock2.h, so has to be included after it. #include +#define CPPHTTPLIB_HAVE_AFUNIX_H 1 +#endif +#endif #ifndef WSA_FLAG_NO_HANDLE_INHERIT #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, hints.ai_flags = socket_flags; } +#if !defined(_WIN32) || defined(CPPHTTPLIB_HAVE_AFUNIX_H) if (hints.ai_family == AF_UNIX) { const auto addrlen = host.length(); 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, } return sock; } +#endif auto service = std::to_string(port);