1616 */
1717
1818#if defined(_WIN32) && !defined(_WIN64)
19- #error \
19+ #warning \
2020 " cpp-httplib doesn't support 32-bit Windows. Please use a 64-bit compiler."
2121#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ < 8
2222#warning \
9898#endif
9999
100100#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND
101- #ifdef _WIN64
101+ #ifdef _WIN32
102102#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 1000
103103#else
104104#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0
184184 * Headers
185185 */
186186
187- #ifdef _WIN64
187+ #ifdef _WIN32
188188#ifndef _CRT_SECURE_NO_WARNINGS
189189#define _CRT_SECURE_NO_WARNINGS
190190#endif // _CRT_SECURE_NO_WARNINGS
@@ -235,7 +235,7 @@ using nfds_t = unsigned long;
235235using socket_t = SOCKET;
236236using socklen_t = int ;
237237
238- #else // not _WIN64
238+ #else // not _WIN32
239239
240240#include < arpa/inet.h>
241241#if !defined(_AIX) && !defined(__MVS__)
@@ -266,7 +266,7 @@ using socket_t = int;
266266#ifndef INVALID_SOCKET
267267#define INVALID_SOCKET (-1 )
268268#endif
269- #endif // _WIN64
269+ #endif // _WIN32
270270
271271#if defined(__APPLE__)
272272#include < TargetConditionals.h>
@@ -311,7 +311,7 @@ using socket_t = int;
311311 // CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
312312
313313#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
314- #ifdef _WIN64
314+ #ifdef _WIN32
315315#include < wincrypt.h>
316316
317317// these are defined in wincrypt.h and it breaks compilation if BoringSSL is
@@ -324,7 +324,7 @@ using socket_t = int;
324324#ifdef _MSC_VER
325325#pragma comment(lib, "crypt32.lib")
326326#endif
327- #endif // _WIN64
327+ #endif // _WIN32
328328
329329#if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
330330#if TARGET_OS_OSX
@@ -337,7 +337,7 @@ using socket_t = int;
337337#include < openssl/ssl.h>
338338#include < openssl/x509v3.h>
339339
340- #if defined(_WIN64 ) && defined(OPENSSL_USE_APPLINK)
340+ #if defined(_WIN32 ) && defined(OPENSSL_USE_APPLINK)
341341#include < openssl/applink.c>
342342#endif
343343
@@ -2086,7 +2086,7 @@ namespace detail {
20862086inline bool set_socket_opt_impl (socket_t sock, int level, int optname,
20872087 const void *optval, socklen_t optlen) {
20882088 return setsockopt (sock, level, optname,
2089- #ifdef _WIN64
2089+ #ifdef _WIN32
20902090 reinterpret_cast <const char *>(optval),
20912091#else
20922092 optval,
@@ -2100,7 +2100,7 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
21002100
21012101inline bool set_socket_opt_time (socket_t sock, int level, int optname,
21022102 time_t sec, time_t usec) {
2103- #ifdef _WIN64
2103+ #ifdef _WIN32
21042104 auto timeout = static_cast <uint32_t >(sec * 1000 + usec / 1000 );
21052105#else
21062106 timeval timeout;
@@ -2378,7 +2378,7 @@ make_basic_authentication_header(const std::string &username,
23782378
23792379namespace detail {
23802380
2381- #if defined(_WIN64 )
2381+ #if defined(_WIN32 )
23822382inline std::wstring u8string_to_wstring (const char *s) {
23832383 std::wstring ws;
23842384 auto len = static_cast <int >(strlen (s));
@@ -2400,7 +2400,7 @@ struct FileStat {
24002400 bool is_dir () const ;
24012401
24022402private:
2403- #if defined(_WIN64 )
2403+ #if defined(_WIN32 )
24042404 struct _stat st_;
24052405#else
24062406 struct stat st_;
@@ -2641,7 +2641,7 @@ class mmap {
26412641 const char *data () const ;
26422642
26432643private:
2644- #if defined(_WIN64 )
2644+ #if defined(_WIN32 )
26452645 HANDLE hFile_ = NULL ;
26462646 HANDLE hMapping_ = NULL ;
26472647#else
@@ -2862,7 +2862,7 @@ inline bool is_valid_path(const std::string &path) {
28622862}
28632863
28642864inline FileStat::FileStat (const std::string &path) {
2865- #if defined(_WIN64 )
2865+ #if defined(_WIN32 )
28662866 auto wpath = u8string_to_wstring (path.c_str ());
28672867 ret_ = _wstat (wpath.c_str (), &st_);
28682868#else
@@ -3074,7 +3074,7 @@ inline mmap::~mmap() { close(); }
30743074inline bool mmap::open (const char *path) {
30753075 close ();
30763076
3077- #if defined(_WIN64 )
3077+ #if defined(_WIN32 )
30783078 auto wpath = u8string_to_wstring (path);
30793079 if (wpath.empty ()) { return false ; }
30803080
@@ -3151,7 +3151,7 @@ inline const char *mmap::data() const {
31513151}
31523152
31533153inline void mmap::close () {
3154- #if defined(_WIN64 )
3154+ #if defined(_WIN32 )
31553155 if (addr_) {
31563156 ::UnmapViewOfFile (addr_);
31573157 addr_ = nullptr ;
@@ -3182,7 +3182,7 @@ inline void mmap::close() {
31823182 size_ = 0 ;
31833183}
31843184inline int close_socket (socket_t sock) {
3185- #ifdef _WIN64
3185+ #ifdef _WIN32
31863186 return closesocket (sock);
31873187#else
31883188 return close (sock);
@@ -3205,7 +3205,7 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
32053205inline ssize_t read_socket (socket_t sock, void *ptr, size_t size, int flags) {
32063206 return handle_EINTR ([&]() {
32073207 return recv (sock,
3208- #ifdef _WIN64
3208+ #ifdef _WIN32
32093209 static_cast <char *>(ptr), static_cast <int >(size),
32103210#else
32113211 ptr, size,
@@ -3218,7 +3218,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
32183218 int flags) {
32193219 return handle_EINTR ([&]() {
32203220 return send (sock,
3221- #ifdef _WIN64
3221+ #ifdef _WIN32
32223222 static_cast <const char *>(ptr), static_cast <int >(size),
32233223#else
32243224 ptr, size,
@@ -3228,7 +3228,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
32283228}
32293229
32303230inline int poll_wrapper (struct pollfd *fds, nfds_t nfds, int timeout) {
3231- #ifdef _WIN64
3231+ #ifdef _WIN32
32323232 return ::WSAPoll (fds, nfds, timeout);
32333233#else
32343234 return ::poll (fds, nfds, timeout);
@@ -3487,7 +3487,7 @@ inline bool process_client_socket(
34873487}
34883488
34893489inline int shutdown_socket (socket_t sock) {
3490- #ifdef _WIN64
3490+ #ifdef _WIN32
34913491 return shutdown (sock, SD_BOTH);
34923492#else
34933493 return shutdown (sock, SHUT_RDWR);
@@ -3522,7 +3522,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
35223522 return getaddrinfo (node, service, hints, res);
35233523 }
35243524
3525- #ifdef _WIN64
3525+ #ifdef _WIN32
35263526 // Windows-specific implementation using GetAddrInfoEx with overlapped I/O
35273527 OVERLAPPED overlapped = {0 };
35283528 HANDLE event = CreateEventW (nullptr , TRUE , FALSE , nullptr );
@@ -3855,7 +3855,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
38553855 hints.ai_flags = socket_flags;
38563856 }
38573857
3858- #if !defined(_WIN64 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3858+ #if !defined(_WIN32 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
38593859 if (hints.ai_family == AF_UNIX) {
38603860 const auto addrlen = host.length ();
38613861 if (addrlen > sizeof (sockaddr_un::sun_path)) { return INVALID_SOCKET; }
@@ -3879,14 +3879,14 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
38793879 sizeof (addr) - sizeof (addr.sun_path ) + addrlen);
38803880
38813881#ifndef SOCK_CLOEXEC
3882- #ifndef _WIN64
3882+ #ifndef _WIN32
38833883 fcntl (sock, F_SETFD, FD_CLOEXEC);
38843884#endif
38853885#endif
38863886
38873887 if (socket_options) { socket_options (sock); }
38883888
3889- #ifdef _WIN64
3889+ #ifdef _WIN32
38903890 // Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
38913891 // remove the option.
38923892 detail::set_socket_opt (sock, SOL_SOCKET, SO_REUSEADDR, 0 );
@@ -3915,7 +3915,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
39153915
39163916 for (auto rp = result; rp; rp = rp->ai_next ) {
39173917 // Create a socket
3918- #ifdef _WIN64
3918+ #ifdef _WIN32
39193919 auto sock =
39203920 WSASocketW (rp->ai_family , rp->ai_socktype , rp->ai_protocol , nullptr , 0 ,
39213921 WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED);
@@ -3948,7 +3948,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
39483948#endif
39493949 if (sock == INVALID_SOCKET) { continue ; }
39503950
3951- #if !defined _WIN64 && !defined SOCK_CLOEXEC
3951+ #if !defined _WIN32 && !defined SOCK_CLOEXEC
39523952 if (fcntl (sock, F_SETFD, FD_CLOEXEC) == -1 ) {
39533953 close_socket (sock);
39543954 continue ;
@@ -3976,7 +3976,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
39763976}
39773977
39783978inline void set_nonblocking (socket_t sock, bool nonblocking) {
3979- #ifdef _WIN64
3979+ #ifdef _WIN32
39803980 auto flags = nonblocking ? 1UL : 0UL ;
39813981 ioctlsocket (sock, FIONBIO, &flags);
39823982#else
@@ -3987,7 +3987,7 @@ inline void set_nonblocking(socket_t sock, bool nonblocking) {
39873987}
39883988
39893989inline bool is_connection_error () {
3990- #ifdef _WIN64
3990+ #ifdef _WIN32
39913991 return WSAGetLastError () != WSAEWOULDBLOCK;
39923992#else
39933993 return errno != EINPROGRESS;
@@ -4021,7 +4021,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
40214021 return ret;
40224022}
40234023
4024- #if !defined _WIN64 && !defined ANDROID && !defined _AIX && !defined __MVS__
4024+ #if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__
40254025#define USE_IF2IP
40264026#endif
40274027
@@ -4160,7 +4160,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
41604160
41614161 if (!getpeername (sock, reinterpret_cast <struct sockaddr *>(&addr),
41624162 &addr_len)) {
4163- #ifndef _WIN64
4163+ #ifndef _WIN32
41644164 if (addr.ss_family == AF_UNIX) {
41654165#if defined(__linux__)
41664166 struct ucred ucred;
@@ -6226,7 +6226,7 @@ inline bool is_ssl_peer_could_be_closed(SSL *ssl, socket_t sock) {
62266226 SSL_get_error (ssl, 0 ) == SSL_ERROR_ZERO_RETURN;
62276227}
62286228
6229- #ifdef _WIN64
6229+ #ifdef _WIN32
62306230// NOTE: This code came up with the following stackoverflow post:
62316231// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store
62326232inline bool load_system_certs_on_windows (X509_STORE *store) {
@@ -6342,10 +6342,10 @@ inline bool load_system_certs_on_macos(X509_STORE *store) {
63426342
63436343 return result;
63446344}
6345- #endif // _WIN64
6345+ #endif // _WIN32
63466346#endif // CPPHTTPLIB_OPENSSL_SUPPORT
63476347
6348- #ifdef _WIN64
6348+ #ifdef _WIN32
63496349class WSInit {
63506350public:
63516351 WSInit () {
@@ -7041,7 +7041,7 @@ inline bool SocketStream::wait_writable() const {
70417041}
70427042
70437043inline ssize_t SocketStream::read (char *ptr, size_t size) {
7044- #ifdef _WIN64
7044+ #ifdef _WIN32
70457045 size =
70467046 (std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
70477047#else
@@ -7089,7 +7089,7 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
70897089inline ssize_t SocketStream::write (const char *ptr, size_t size) {
70907090 if (!wait_writable ()) { return -1 ; }
70917091
7092- #if defined(_WIN64 ) && !defined(_WIN64)
7092+ #if defined(_WIN32 ) && !defined(_WIN64)
70937093 size =
70947094 (std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
70957095#endif
@@ -7252,7 +7252,7 @@ inline bool RegexMatcher::match(Request &request) const {
72527252inline Server::Server ()
72537253 : new_task_queue (
72547254 [] { return new ThreadPool (CPPHTTPLIB_THREAD_POOL_COUNT); }) {
7255- #ifndef _WIN64
7255+ #ifndef _WIN32
72567256 signal (SIGPIPE, SIG_IGN);
72577257#endif
72587258}
@@ -7950,7 +7950,7 @@ inline bool Server::listen_internal() {
79507950 std::unique_ptr<TaskQueue> task_queue (new_task_queue ());
79517951
79527952 while (svr_sock_ != INVALID_SOCKET) {
7953- #ifndef _WIN64
7953+ #ifndef _WIN32
79547954 if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0 ) {
79557955#endif
79567956 auto val = detail::select_read (svr_sock_, idle_interval_sec_,
@@ -7959,11 +7959,11 @@ inline bool Server::listen_internal() {
79597959 task_queue->on_idle ();
79607960 continue ;
79617961 }
7962- #ifndef _WIN64
7962+ #ifndef _WIN32
79637963 }
79647964#endif
79657965
7966- #if defined _WIN64
7966+ #if defined _WIN32
79677967 // sockets connected via WASAccept inherit flags NO_HANDLE_INHERIT,
79687968 // OVERLAPPED
79697969 socket_t sock = WSAAccept (svr_sock_, nullptr , nullptr , nullptr , 0 );
@@ -10571,7 +10571,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
1057110571 if (ret < 0 ) {
1057210572 auto err = SSL_get_error (ssl_, ret);
1057310573 auto n = 1000 ;
10574- #ifdef _WIN64
10574+ #ifdef _WIN32
1057510575 while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
1057610576 (err == SSL_ERROR_SYSCALL &&
1057710577 WSAGetLastError () == WSAETIMEDOUT))) {
@@ -10606,7 +10606,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
1060610606 if (ret < 0 ) {
1060710607 auto err = SSL_get_error (ssl_, ret);
1060810608 auto n = 1000 ;
10609- #ifdef _WIN64
10609+ #ifdef _WIN32
1061010610 while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
1061110611 (err == SSL_ERROR_SYSCALL &&
1061210612 WSAGetLastError () == WSAETIMEDOUT))) {
@@ -11000,13 +11000,13 @@ inline bool SSLClient::load_certs() {
1100011000 }
1100111001 } else {
1100211002 auto loaded = false ;
11003- #ifdef _WIN64
11003+ #ifdef _WIN32
1100411004 loaded =
1100511005 detail::load_system_certs_on_windows (SSL_CTX_get_cert_store (ctx_));
1100611006#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \
1100711007 defined (TARGET_OS_OSX)
1100811008 loaded = detail::load_system_certs_on_macos (SSL_CTX_get_cert_store (ctx_));
11009- #endif // _WIN64
11009+ #endif // _WIN32
1101011010 if (!loaded) { SSL_CTX_set_default_verify_paths (ctx_); }
1101111011 }
1101211012 });
0 commit comments