16
16
*/
17
17
18
18
#if defined(_WIN32) && !defined(_WIN64)
19
- #error \
19
+ #warning \
20
20
" cpp-httplib doesn't support 32-bit Windows. Please use a 64-bit compiler."
21
21
#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ < 8
22
22
#warning \
98
98
#endif
99
99
100
100
#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND
101
- #ifdef _WIN64
101
+ #ifdef _WIN32
102
102
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 1000
103
103
#else
104
104
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0
184
184
* Headers
185
185
*/
186
186
187
- #ifdef _WIN64
187
+ #ifdef _WIN32
188
188
#ifndef _CRT_SECURE_NO_WARNINGS
189
189
#define _CRT_SECURE_NO_WARNINGS
190
190
#endif // _CRT_SECURE_NO_WARNINGS
@@ -235,7 +235,7 @@ using nfds_t = unsigned long;
235
235
using socket_t = SOCKET;
236
236
using socklen_t = int ;
237
237
238
- #else // not _WIN64
238
+ #else // not _WIN32
239
239
240
240
#include < arpa/inet.h>
241
241
#if !defined(_AIX) && !defined(__MVS__)
@@ -266,7 +266,7 @@ using socket_t = int;
266
266
#ifndef INVALID_SOCKET
267
267
#define INVALID_SOCKET (-1 )
268
268
#endif
269
- #endif // _WIN64
269
+ #endif // _WIN32
270
270
271
271
#if defined(__APPLE__)
272
272
#include < TargetConditionals.h>
@@ -311,7 +311,7 @@ using socket_t = int;
311
311
// CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
312
312
313
313
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
314
- #ifdef _WIN64
314
+ #ifdef _WIN32
315
315
#include < wincrypt.h>
316
316
317
317
// these are defined in wincrypt.h and it breaks compilation if BoringSSL is
@@ -324,7 +324,7 @@ using socket_t = int;
324
324
#ifdef _MSC_VER
325
325
#pragma comment(lib, "crypt32.lib")
326
326
#endif
327
- #endif // _WIN64
327
+ #endif // _WIN32
328
328
329
329
#if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
330
330
#if TARGET_OS_OSX
@@ -337,7 +337,7 @@ using socket_t = int;
337
337
#include < openssl/ssl.h>
338
338
#include < openssl/x509v3.h>
339
339
340
- #if defined(_WIN64 ) && defined(OPENSSL_USE_APPLINK)
340
+ #if defined(_WIN32 ) && defined(OPENSSL_USE_APPLINK)
341
341
#include < openssl/applink.c>
342
342
#endif
343
343
@@ -2086,7 +2086,7 @@ namespace detail {
2086
2086
inline bool set_socket_opt_impl (socket_t sock, int level, int optname,
2087
2087
const void *optval, socklen_t optlen) {
2088
2088
return setsockopt (sock, level, optname,
2089
- #ifdef _WIN64
2089
+ #ifdef _WIN32
2090
2090
reinterpret_cast <const char *>(optval),
2091
2091
#else
2092
2092
optval,
@@ -2100,7 +2100,7 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
2100
2100
2101
2101
inline bool set_socket_opt_time (socket_t sock, int level, int optname,
2102
2102
time_t sec, time_t usec) {
2103
- #ifdef _WIN64
2103
+ #ifdef _WIN32
2104
2104
auto timeout = static_cast <uint32_t >(sec * 1000 + usec / 1000 );
2105
2105
#else
2106
2106
timeval timeout;
@@ -2378,7 +2378,7 @@ make_basic_authentication_header(const std::string &username,
2378
2378
2379
2379
namespace detail {
2380
2380
2381
- #if defined(_WIN64 )
2381
+ #if defined(_WIN32 )
2382
2382
inline std::wstring u8string_to_wstring (const char *s) {
2383
2383
std::wstring ws;
2384
2384
auto len = static_cast <int >(strlen (s));
@@ -2400,7 +2400,7 @@ struct FileStat {
2400
2400
bool is_dir () const ;
2401
2401
2402
2402
private:
2403
- #if defined(_WIN64 )
2403
+ #if defined(_WIN32 )
2404
2404
struct _stat st_;
2405
2405
#else
2406
2406
struct stat st_;
@@ -2641,7 +2641,7 @@ class mmap {
2641
2641
const char *data () const ;
2642
2642
2643
2643
private:
2644
- #if defined(_WIN64 )
2644
+ #if defined(_WIN32 )
2645
2645
HANDLE hFile_ = NULL ;
2646
2646
HANDLE hMapping_ = NULL ;
2647
2647
#else
@@ -2862,7 +2862,7 @@ inline bool is_valid_path(const std::string &path) {
2862
2862
}
2863
2863
2864
2864
inline FileStat::FileStat (const std::string &path) {
2865
- #if defined(_WIN64 )
2865
+ #if defined(_WIN32 )
2866
2866
auto wpath = u8string_to_wstring (path.c_str ());
2867
2867
ret_ = _wstat (wpath.c_str (), &st_);
2868
2868
#else
@@ -3074,7 +3074,7 @@ inline mmap::~mmap() { close(); }
3074
3074
inline bool mmap::open (const char *path) {
3075
3075
close ();
3076
3076
3077
- #if defined(_WIN64 )
3077
+ #if defined(_WIN32 )
3078
3078
auto wpath = u8string_to_wstring (path);
3079
3079
if (wpath.empty ()) { return false ; }
3080
3080
@@ -3151,7 +3151,7 @@ inline const char *mmap::data() const {
3151
3151
}
3152
3152
3153
3153
inline void mmap::close () {
3154
- #if defined(_WIN64 )
3154
+ #if defined(_WIN32 )
3155
3155
if (addr_) {
3156
3156
::UnmapViewOfFile (addr_);
3157
3157
addr_ = nullptr ;
@@ -3182,7 +3182,7 @@ inline void mmap::close() {
3182
3182
size_ = 0 ;
3183
3183
}
3184
3184
inline int close_socket (socket_t sock) {
3185
- #ifdef _WIN64
3185
+ #ifdef _WIN32
3186
3186
return closesocket (sock);
3187
3187
#else
3188
3188
return close (sock);
@@ -3205,7 +3205,7 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
3205
3205
inline ssize_t read_socket (socket_t sock, void *ptr, size_t size, int flags) {
3206
3206
return handle_EINTR ([&]() {
3207
3207
return recv (sock,
3208
- #ifdef _WIN64
3208
+ #ifdef _WIN32
3209
3209
static_cast <char *>(ptr), static_cast <int >(size),
3210
3210
#else
3211
3211
ptr, size,
@@ -3218,7 +3218,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
3218
3218
int flags) {
3219
3219
return handle_EINTR ([&]() {
3220
3220
return send (sock,
3221
- #ifdef _WIN64
3221
+ #ifdef _WIN32
3222
3222
static_cast <const char *>(ptr), static_cast <int >(size),
3223
3223
#else
3224
3224
ptr, size,
@@ -3228,7 +3228,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
3228
3228
}
3229
3229
3230
3230
inline int poll_wrapper (struct pollfd *fds, nfds_t nfds, int timeout) {
3231
- #ifdef _WIN64
3231
+ #ifdef _WIN32
3232
3232
return ::WSAPoll (fds, nfds, timeout);
3233
3233
#else
3234
3234
return ::poll (fds, nfds, timeout);
@@ -3487,7 +3487,7 @@ inline bool process_client_socket(
3487
3487
}
3488
3488
3489
3489
inline int shutdown_socket (socket_t sock) {
3490
- #ifdef _WIN64
3490
+ #ifdef _WIN32
3491
3491
return shutdown (sock, SD_BOTH);
3492
3492
#else
3493
3493
return shutdown (sock, SHUT_RDWR);
@@ -3522,7 +3522,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
3522
3522
return getaddrinfo (node, service, hints, res);
3523
3523
}
3524
3524
3525
- #ifdef _WIN64
3525
+ #ifdef _WIN32
3526
3526
// Windows-specific implementation using GetAddrInfoEx with overlapped I/O
3527
3527
OVERLAPPED overlapped = {0 };
3528
3528
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,
3855
3855
hints.ai_flags = socket_flags;
3856
3856
}
3857
3857
3858
- #if !defined(_WIN64 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3858
+ #if !defined(_WIN32 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3859
3859
if (hints.ai_family == AF_UNIX) {
3860
3860
const auto addrlen = host.length ();
3861
3861
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,
3879
3879
sizeof (addr) - sizeof (addr.sun_path ) + addrlen);
3880
3880
3881
3881
#ifndef SOCK_CLOEXEC
3882
- #ifndef _WIN64
3882
+ #ifndef _WIN32
3883
3883
fcntl (sock, F_SETFD, FD_CLOEXEC);
3884
3884
#endif
3885
3885
#endif
3886
3886
3887
3887
if (socket_options) { socket_options (sock); }
3888
3888
3889
- #ifdef _WIN64
3889
+ #ifdef _WIN32
3890
3890
// Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
3891
3891
// remove the option.
3892
3892
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,
3915
3915
3916
3916
for (auto rp = result; rp; rp = rp->ai_next ) {
3917
3917
// Create a socket
3918
- #ifdef _WIN64
3918
+ #ifdef _WIN32
3919
3919
auto sock =
3920
3920
WSASocketW (rp->ai_family , rp->ai_socktype , rp->ai_protocol , nullptr , 0 ,
3921
3921
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,
3948
3948
#endif
3949
3949
if (sock == INVALID_SOCKET) { continue ; }
3950
3950
3951
- #if !defined _WIN64 && !defined SOCK_CLOEXEC
3951
+ #if !defined _WIN32 && !defined SOCK_CLOEXEC
3952
3952
if (fcntl (sock, F_SETFD, FD_CLOEXEC) == -1 ) {
3953
3953
close_socket (sock);
3954
3954
continue ;
@@ -3976,7 +3976,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3976
3976
}
3977
3977
3978
3978
inline void set_nonblocking (socket_t sock, bool nonblocking) {
3979
- #ifdef _WIN64
3979
+ #ifdef _WIN32
3980
3980
auto flags = nonblocking ? 1UL : 0UL ;
3981
3981
ioctlsocket (sock, FIONBIO, &flags);
3982
3982
#else
@@ -3987,7 +3987,7 @@ inline void set_nonblocking(socket_t sock, bool nonblocking) {
3987
3987
}
3988
3988
3989
3989
inline bool is_connection_error () {
3990
- #ifdef _WIN64
3990
+ #ifdef _WIN32
3991
3991
return WSAGetLastError () != WSAEWOULDBLOCK;
3992
3992
#else
3993
3993
return errno != EINPROGRESS;
@@ -4021,7 +4021,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
4021
4021
return ret;
4022
4022
}
4023
4023
4024
- #if !defined _WIN64 && !defined ANDROID && !defined _AIX && !defined __MVS__
4024
+ #if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__
4025
4025
#define USE_IF2IP
4026
4026
#endif
4027
4027
@@ -4160,7 +4160,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
4160
4160
4161
4161
if (!getpeername (sock, reinterpret_cast <struct sockaddr *>(&addr),
4162
4162
&addr_len)) {
4163
- #ifndef _WIN64
4163
+ #ifndef _WIN32
4164
4164
if (addr.ss_family == AF_UNIX) {
4165
4165
#if defined(__linux__)
4166
4166
struct ucred ucred;
@@ -6226,7 +6226,7 @@ inline bool is_ssl_peer_could_be_closed(SSL *ssl, socket_t sock) {
6226
6226
SSL_get_error (ssl, 0 ) == SSL_ERROR_ZERO_RETURN;
6227
6227
}
6228
6228
6229
- #ifdef _WIN64
6229
+ #ifdef _WIN32
6230
6230
// NOTE: This code came up with the following stackoverflow post:
6231
6231
// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store
6232
6232
inline bool load_system_certs_on_windows (X509_STORE *store) {
@@ -6342,10 +6342,10 @@ inline bool load_system_certs_on_macos(X509_STORE *store) {
6342
6342
6343
6343
return result;
6344
6344
}
6345
- #endif // _WIN64
6345
+ #endif // _WIN32
6346
6346
#endif // CPPHTTPLIB_OPENSSL_SUPPORT
6347
6347
6348
- #ifdef _WIN64
6348
+ #ifdef _WIN32
6349
6349
class WSInit {
6350
6350
public:
6351
6351
WSInit () {
@@ -7041,7 +7041,7 @@ inline bool SocketStream::wait_writable() const {
7041
7041
}
7042
7042
7043
7043
inline ssize_t SocketStream::read (char *ptr, size_t size) {
7044
- #ifdef _WIN64
7044
+ #ifdef _WIN32
7045
7045
size =
7046
7046
(std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
7047
7047
#else
@@ -7089,7 +7089,7 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
7089
7089
inline ssize_t SocketStream::write (const char *ptr, size_t size) {
7090
7090
if (!wait_writable ()) { return -1 ; }
7091
7091
7092
- #if defined(_WIN64 ) && !defined(_WIN64)
7092
+ #if defined(_WIN32 ) && !defined(_WIN64)
7093
7093
size =
7094
7094
(std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
7095
7095
#endif
@@ -7252,7 +7252,7 @@ inline bool RegexMatcher::match(Request &request) const {
7252
7252
inline Server::Server ()
7253
7253
: new_task_queue (
7254
7254
[] { return new ThreadPool (CPPHTTPLIB_THREAD_POOL_COUNT); }) {
7255
- #ifndef _WIN64
7255
+ #ifndef _WIN32
7256
7256
signal (SIGPIPE, SIG_IGN);
7257
7257
#endif
7258
7258
}
@@ -7950,7 +7950,7 @@ inline bool Server::listen_internal() {
7950
7950
std::unique_ptr<TaskQueue> task_queue (new_task_queue ());
7951
7951
7952
7952
while (svr_sock_ != INVALID_SOCKET) {
7953
- #ifndef _WIN64
7953
+ #ifndef _WIN32
7954
7954
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0 ) {
7955
7955
#endif
7956
7956
auto val = detail::select_read (svr_sock_, idle_interval_sec_,
@@ -7959,11 +7959,11 @@ inline bool Server::listen_internal() {
7959
7959
task_queue->on_idle ();
7960
7960
continue ;
7961
7961
}
7962
- #ifndef _WIN64
7962
+ #ifndef _WIN32
7963
7963
}
7964
7964
#endif
7965
7965
7966
- #if defined _WIN64
7966
+ #if defined _WIN32
7967
7967
// sockets connected via WASAccept inherit flags NO_HANDLE_INHERIT,
7968
7968
// OVERLAPPED
7969
7969
socket_t sock = WSAAccept (svr_sock_, nullptr , nullptr , nullptr , 0 );
@@ -10571,7 +10571,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
10571
10571
if (ret < 0 ) {
10572
10572
auto err = SSL_get_error (ssl_, ret);
10573
10573
auto n = 1000 ;
10574
- #ifdef _WIN64
10574
+ #ifdef _WIN32
10575
10575
while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
10576
10576
(err == SSL_ERROR_SYSCALL &&
10577
10577
WSAGetLastError () == WSAETIMEDOUT))) {
@@ -10606,7 +10606,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
10606
10606
if (ret < 0 ) {
10607
10607
auto err = SSL_get_error (ssl_, ret);
10608
10608
auto n = 1000 ;
10609
- #ifdef _WIN64
10609
+ #ifdef _WIN32
10610
10610
while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
10611
10611
(err == SSL_ERROR_SYSCALL &&
10612
10612
WSAGetLastError () == WSAETIMEDOUT))) {
@@ -11000,13 +11000,13 @@ inline bool SSLClient::load_certs() {
11000
11000
}
11001
11001
} else {
11002
11002
auto loaded = false ;
11003
- #ifdef _WIN64
11003
+ #ifdef _WIN32
11004
11004
loaded =
11005
11005
detail::load_system_certs_on_windows (SSL_CTX_get_cert_store (ctx_));
11006
11006
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \
11007
11007
defined (TARGET_OS_OSX)
11008
11008
loaded = detail::load_system_certs_on_macos (SSL_CTX_get_cert_store (ctx_));
11009
- #endif // _WIN64
11009
+ #endif // _WIN32
11010
11010
if (!loaded) { SSL_CTX_set_default_verify_paths (ctx_); }
11011
11011
}
11012
11012
});
0 commit comments