yhirose пре 6 месеци
родитељ
комит
fbee136dca
1 измењених фајлова са 44 додато и 44 уклоњено
  1. 44 44
      httplib.h

+ 44 - 44
httplib.h

@@ -16,7 +16,7 @@
  */
 
 #if defined(_WIN32) && !defined(_WIN64)
-#error                                                                         \
+#warning                                                                       \
     "cpp-httplib doesn't support 32-bit Windows. Please use a 64-bit compiler."
 #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ < 8
 #warning                                                                       \
@@ -98,7 +98,7 @@
 #endif
 
 #ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND
-#ifdef _WIN64
+#ifdef _WIN32
 #define CPPHTTPLIB_IDLE_INTERVAL_USECOND 1000
 #else
 #define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0
@@ -184,7 +184,7 @@
  * Headers
  */
 
-#ifdef _WIN64
+#ifdef _WIN32
 #ifndef _CRT_SECURE_NO_WARNINGS
 #define _CRT_SECURE_NO_WARNINGS
 #endif //_CRT_SECURE_NO_WARNINGS
@@ -235,7 +235,7 @@ using nfds_t = unsigned long;
 using socket_t = SOCKET;
 using socklen_t = int;
 
-#else // not _WIN64
+#else // not _WIN32
 
 #include <arpa/inet.h>
 #if !defined(_AIX) && !defined(__MVS__)
@@ -266,7 +266,7 @@ using socket_t = int;
 #ifndef INVALID_SOCKET
 #define INVALID_SOCKET (-1)
 #endif
-#endif //_WIN64
+#endif //_WIN32
 
 #if defined(__APPLE__)
 #include <TargetConditionals.h>
@@ -311,7 +311,7 @@ using socket_t = int;
        // CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
-#ifdef _WIN64
+#ifdef _WIN32
 #include <wincrypt.h>
 
 // these are defined in wincrypt.h and it breaks compilation if BoringSSL is
@@ -324,7 +324,7 @@ using socket_t = int;
 #ifdef _MSC_VER
 #pragma comment(lib, "crypt32.lib")
 #endif
-#endif // _WIN64
+#endif // _WIN32
 
 #if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
 #if TARGET_OS_OSX
@@ -337,7 +337,7 @@ using socket_t = int;
 #include <openssl/ssl.h>
 #include <openssl/x509v3.h>
 
-#if defined(_WIN64) && defined(OPENSSL_USE_APPLINK)
+#if defined(_WIN32) && defined(OPENSSL_USE_APPLINK)
 #include <openssl/applink.c>
 #endif
 
@@ -2086,7 +2086,7 @@ namespace detail {
 inline bool set_socket_opt_impl(socket_t sock, int level, int optname,
                                 const void *optval, socklen_t optlen) {
   return setsockopt(sock, level, optname,
-#ifdef _WIN64
+#ifdef _WIN32
                     reinterpret_cast<const char *>(optval),
 #else
                     optval,
@@ -2100,7 +2100,7 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
 
 inline bool set_socket_opt_time(socket_t sock, int level, int optname,
                                 time_t sec, time_t usec) {
-#ifdef _WIN64
+#ifdef _WIN32
   auto timeout = static_cast<uint32_t>(sec * 1000 + usec / 1000);
 #else
   timeval timeout;
@@ -2378,7 +2378,7 @@ make_basic_authentication_header(const std::string &username,
 
 namespace detail {
 
-#if defined(_WIN64)
+#if defined(_WIN32)
 inline std::wstring u8string_to_wstring(const char *s) {
   std::wstring ws;
   auto len = static_cast<int>(strlen(s));
@@ -2400,7 +2400,7 @@ struct FileStat {
   bool is_dir() const;
 
 private:
-#if defined(_WIN64)
+#if defined(_WIN32)
   struct _stat st_;
 #else
   struct stat st_;
@@ -2641,7 +2641,7 @@ public:
   const char *data() const;
 
 private:
-#if defined(_WIN64)
+#if defined(_WIN32)
   HANDLE hFile_ = NULL;
   HANDLE hMapping_ = NULL;
 #else
@@ -2862,7 +2862,7 @@ inline bool is_valid_path(const std::string &path) {
 }
 
 inline FileStat::FileStat(const std::string &path) {
-#if defined(_WIN64)
+#if defined(_WIN32)
   auto wpath = u8string_to_wstring(path.c_str());
   ret_ = _wstat(wpath.c_str(), &st_);
 #else
@@ -3074,7 +3074,7 @@ inline mmap::~mmap() { close(); }
 inline bool mmap::open(const char *path) {
   close();
 
-#if defined(_WIN64)
+#if defined(_WIN32)
   auto wpath = u8string_to_wstring(path);
   if (wpath.empty()) { return false; }
 
@@ -3151,7 +3151,7 @@ inline const char *mmap::data() const {
 }
 
 inline void mmap::close() {
-#if defined(_WIN64)
+#if defined(_WIN32)
   if (addr_) {
     ::UnmapViewOfFile(addr_);
     addr_ = nullptr;
@@ -3182,7 +3182,7 @@ inline void mmap::close() {
   size_ = 0;
 }
 inline int close_socket(socket_t sock) {
-#ifdef _WIN64
+#ifdef _WIN32
   return closesocket(sock);
 #else
   return close(sock);
@@ -3205,7 +3205,7 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
 inline ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags) {
   return handle_EINTR([&]() {
     return recv(sock,
-#ifdef _WIN64
+#ifdef _WIN32
                 static_cast<char *>(ptr), static_cast<int>(size),
 #else
                 ptr, size,
@@ -3218,7 +3218,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
                            int flags) {
   return handle_EINTR([&]() {
     return send(sock,
-#ifdef _WIN64
+#ifdef _WIN32
                 static_cast<const char *>(ptr), static_cast<int>(size),
 #else
                 ptr, size,
@@ -3228,7 +3228,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
 }
 
 inline int poll_wrapper(struct pollfd *fds, nfds_t nfds, int timeout) {
-#ifdef _WIN64
+#ifdef _WIN32
   return ::WSAPoll(fds, nfds, timeout);
 #else
   return ::poll(fds, nfds, timeout);
@@ -3487,7 +3487,7 @@ inline bool process_client_socket(
 }
 
 inline int shutdown_socket(socket_t sock) {
-#ifdef _WIN64
+#ifdef _WIN32
   return shutdown(sock, SD_BOTH);
 #else
   return shutdown(sock, SHUT_RDWR);
@@ -3522,7 +3522,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
     return getaddrinfo(node, service, hints, res);
   }
 
-#ifdef _WIN64
+#ifdef _WIN32
   // Windows-specific implementation using GetAddrInfoEx with overlapped I/O
   OVERLAPPED overlapped = {0};
   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,
     hints.ai_flags = socket_flags;
   }
 
-#if !defined(_WIN64) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
+#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; }
@@ -3879,14 +3879,14 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
           sizeof(addr) - sizeof(addr.sun_path) + addrlen);
 
 #ifndef SOCK_CLOEXEC
-#ifndef _WIN64
+#ifndef _WIN32
       fcntl(sock, F_SETFD, FD_CLOEXEC);
 #endif
 #endif
 
       if (socket_options) { socket_options(sock); }
 
-#ifdef _WIN64
+#ifdef _WIN32
       // Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
       // remove the option.
       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,
 
   for (auto rp = result; rp; rp = rp->ai_next) {
     // Create a socket
-#ifdef _WIN64
+#ifdef _WIN32
     auto sock =
         WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0,
                    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,
 #endif
     if (sock == INVALID_SOCKET) { continue; }
 
-#if !defined _WIN64 && !defined SOCK_CLOEXEC
+#if !defined _WIN32 && !defined SOCK_CLOEXEC
     if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) {
       close_socket(sock);
       continue;
@@ -3976,7 +3976,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
 }
 
 inline void set_nonblocking(socket_t sock, bool nonblocking) {
-#ifdef _WIN64
+#ifdef _WIN32
   auto flags = nonblocking ? 1UL : 0UL;
   ioctlsocket(sock, FIONBIO, &flags);
 #else
@@ -3987,7 +3987,7 @@ inline void set_nonblocking(socket_t sock, bool nonblocking) {
 }
 
 inline bool is_connection_error() {
-#ifdef _WIN64
+#ifdef _WIN32
   return WSAGetLastError() != WSAEWOULDBLOCK;
 #else
   return errno != EINPROGRESS;
@@ -4021,7 +4021,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
   return ret;
 }
 
-#if !defined _WIN64 && !defined ANDROID && !defined _AIX && !defined __MVS__
+#if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__
 #define USE_IF2IP
 #endif
 
@@ -4160,7 +4160,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
 
   if (!getpeername(sock, reinterpret_cast<struct sockaddr *>(&addr),
                    &addr_len)) {
-#ifndef _WIN64
+#ifndef _WIN32
     if (addr.ss_family == AF_UNIX) {
 #if defined(__linux__)
       struct ucred ucred;
@@ -6226,7 +6226,7 @@ inline bool is_ssl_peer_could_be_closed(SSL *ssl, socket_t sock) {
          SSL_get_error(ssl, 0) == SSL_ERROR_ZERO_RETURN;
 }
 
-#ifdef _WIN64
+#ifdef _WIN32
 // NOTE: This code came up with the following stackoverflow post:
 // https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store
 inline bool load_system_certs_on_windows(X509_STORE *store) {
@@ -6342,10 +6342,10 @@ inline bool load_system_certs_on_macos(X509_STORE *store) {
 
   return result;
 }
-#endif // _WIN64
+#endif // _WIN32
 #endif // CPPHTTPLIB_OPENSSL_SUPPORT
 
-#ifdef _WIN64
+#ifdef _WIN32
 class WSInit {
 public:
   WSInit() {
@@ -7041,7 +7041,7 @@ inline bool SocketStream::wait_writable() const {
 }
 
 inline ssize_t SocketStream::read(char *ptr, size_t size) {
-#ifdef _WIN64
+#ifdef _WIN32
   size =
       (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
 #else
@@ -7089,7 +7089,7 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
 inline ssize_t SocketStream::write(const char *ptr, size_t size) {
   if (!wait_writable()) { return -1; }
 
-#if defined(_WIN64) && !defined(_WIN64)
+#if defined(_WIN32) && !defined(_WIN64)
   size =
       (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
 #endif
@@ -7252,7 +7252,7 @@ inline bool RegexMatcher::match(Request &request) const {
 inline Server::Server()
     : new_task_queue(
           [] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }) {
-#ifndef _WIN64
+#ifndef _WIN32
   signal(SIGPIPE, SIG_IGN);
 #endif
 }
@@ -7950,7 +7950,7 @@ inline bool Server::listen_internal() {
     std::unique_ptr<TaskQueue> task_queue(new_task_queue());
 
     while (svr_sock_ != INVALID_SOCKET) {
-#ifndef _WIN64
+#ifndef _WIN32
       if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {
 #endif
         auto val = detail::select_read(svr_sock_, idle_interval_sec_,
@@ -7959,11 +7959,11 @@ inline bool Server::listen_internal() {
           task_queue->on_idle();
           continue;
         }
-#ifndef _WIN64
+#ifndef _WIN32
       }
 #endif
 
-#if defined _WIN64
+#if defined _WIN32
       // sockets connected via WASAccept inherit flags NO_HANDLE_INHERIT,
       // OVERLAPPED
       socket_t sock = WSAAccept(svr_sock_, nullptr, nullptr, nullptr, 0);
@@ -10571,7 +10571,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
     if (ret < 0) {
       auto err = SSL_get_error(ssl_, ret);
       auto n = 1000;
-#ifdef _WIN64
+#ifdef _WIN32
       while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
                           (err == SSL_ERROR_SYSCALL &&
                            WSAGetLastError() == WSAETIMEDOUT))) {
@@ -10606,7 +10606,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
     if (ret < 0) {
       auto err = SSL_get_error(ssl_, ret);
       auto n = 1000;
-#ifdef _WIN64
+#ifdef _WIN32
       while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
                           (err == SSL_ERROR_SYSCALL &&
                            WSAGetLastError() == WSAETIMEDOUT))) {
@@ -11000,13 +11000,13 @@ inline bool SSLClient::load_certs() {
       }
     } else {
       auto loaded = false;
-#ifdef _WIN64
+#ifdef _WIN32
       loaded =
           detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_));
 #elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) &&                    \
     defined(TARGET_OS_OSX)
       loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_));
-#endif // _WIN64
+#endif // _WIN32
       if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); }
     }
   });