90
90
#endif
91
91
92
92
#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND
93
- #ifdef _WIN32
93
+ #ifdef _WIN64
94
94
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 1000
95
95
#else
96
96
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0
176
176
* Headers
177
177
*/
178
178
179
- #ifdef _WIN32
179
+ #ifdef _WIN64
180
180
#ifndef _CRT_SECURE_NO_WARNINGS
181
181
#define _CRT_SECURE_NO_WARNINGS
182
182
#endif // _CRT_SECURE_NO_WARNINGS
@@ -227,7 +227,7 @@ using nfds_t = unsigned long;
227
227
using socket_t = SOCKET;
228
228
using socklen_t = int ;
229
229
230
- #else // not _WIN32
230
+ #else // not _WIN64
231
231
232
232
#include < arpa/inet.h>
233
233
#if !defined(_AIX) && !defined(__MVS__)
@@ -258,7 +258,7 @@ using socket_t = int;
258
258
#ifndef INVALID_SOCKET
259
259
#define INVALID_SOCKET (-1 )
260
260
#endif
261
- #endif // _WIN32
261
+ #endif // _WIN64
262
262
263
263
#if defined(__APPLE__)
264
264
#include < TargetConditionals.h>
@@ -303,7 +303,7 @@ using socket_t = int;
303
303
// CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
304
304
305
305
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
306
- #ifdef _WIN32
306
+ #ifdef _WIN64
307
307
#include < wincrypt.h>
308
308
309
309
// these are defined in wincrypt.h and it breaks compilation if BoringSSL is
@@ -316,7 +316,7 @@ using socket_t = int;
316
316
#ifdef _MSC_VER
317
317
#pragma comment(lib, "crypt32.lib")
318
318
#endif
319
- #endif // _WIN32
319
+ #endif // _WIN64
320
320
321
321
#if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
322
322
#if TARGET_OS_OSX
@@ -329,7 +329,7 @@ using socket_t = int;
329
329
#include < openssl/ssl.h>
330
330
#include < openssl/x509v3.h>
331
331
332
- #if defined(_WIN32 ) && defined(OPENSSL_USE_APPLINK)
332
+ #if defined(_WIN64 ) && defined(OPENSSL_USE_APPLINK)
333
333
#include < openssl/applink.c>
334
334
#endif
335
335
@@ -2030,7 +2030,7 @@ namespace detail {
2030
2030
inline bool set_socket_opt_impl (socket_t sock, int level, int optname,
2031
2031
const void *optval, socklen_t optlen) {
2032
2032
return setsockopt (sock, level, optname,
2033
- #ifdef _WIN32
2033
+ #ifdef _WIN64
2034
2034
reinterpret_cast <const char *>(optval),
2035
2035
#else
2036
2036
optval,
@@ -2044,7 +2044,7 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
2044
2044
2045
2045
inline bool set_socket_opt_time (socket_t sock, int level, int optname,
2046
2046
time_t sec, time_t usec) {
2047
- #ifdef _WIN32
2047
+ #ifdef _WIN64
2048
2048
auto timeout = static_cast <uint32_t >(sec * 1000 + usec / 1000 );
2049
2049
#else
2050
2050
timeval timeout;
@@ -2297,7 +2297,7 @@ make_basic_authentication_header(const std::string &username,
2297
2297
2298
2298
namespace detail {
2299
2299
2300
- #if defined(_WIN32 )
2300
+ #if defined(_WIN64 )
2301
2301
inline std::wstring u8string_to_wstring (const char *s) {
2302
2302
std::wstring ws;
2303
2303
auto len = static_cast <int >(strlen (s));
@@ -2319,7 +2319,7 @@ struct FileStat {
2319
2319
bool is_dir () const ;
2320
2320
2321
2321
private:
2322
- #if defined(_WIN32 )
2322
+ #if defined(_WIN64 )
2323
2323
struct _stat st_;
2324
2324
#else
2325
2325
struct stat st_;
@@ -2562,7 +2562,7 @@ class mmap {
2562
2562
const char *data () const ;
2563
2563
2564
2564
private:
2565
- #if defined(_WIN32 )
2565
+ #if defined(_WIN64 )
2566
2566
HANDLE hFile_ = NULL ;
2567
2567
HANDLE hMapping_ = NULL ;
2568
2568
#else
@@ -2783,7 +2783,7 @@ inline bool is_valid_path(const std::string &path) {
2783
2783
}
2784
2784
2785
2785
inline FileStat::FileStat (const std::string &path) {
2786
- #if defined(_WIN32 )
2786
+ #if defined(_WIN64 )
2787
2787
auto wpath = u8string_to_wstring (path.c_str ());
2788
2788
ret_ = _wstat (wpath.c_str (), &st_);
2789
2789
#else
@@ -3032,7 +3032,7 @@ inline mmap::~mmap() { close(); }
3032
3032
inline bool mmap::open (const char *path) {
3033
3033
close ();
3034
3034
3035
- #if defined(_WIN32 )
3035
+ #if defined(_WIN64 )
3036
3036
auto wpath = u8string_to_wstring (path);
3037
3037
if (wpath.empty ()) { return false ; }
3038
3038
@@ -3122,7 +3122,7 @@ inline const char *mmap::data() const {
3122
3122
}
3123
3123
3124
3124
inline void mmap::close () {
3125
- #if defined(_WIN32 )
3125
+ #if defined(_WIN64 )
3126
3126
if (addr_) {
3127
3127
::UnmapViewOfFile (addr_);
3128
3128
addr_ = nullptr ;
@@ -3153,7 +3153,7 @@ inline void mmap::close() {
3153
3153
size_ = 0 ;
3154
3154
}
3155
3155
inline int close_socket (socket_t sock) {
3156
- #ifdef _WIN32
3156
+ #ifdef _WIN64
3157
3157
return closesocket (sock);
3158
3158
#else
3159
3159
return close (sock);
@@ -3176,7 +3176,7 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
3176
3176
inline ssize_t read_socket (socket_t sock, void *ptr, size_t size, int flags) {
3177
3177
return handle_EINTR ([&]() {
3178
3178
return recv (sock,
3179
- #ifdef _WIN32
3179
+ #ifdef _WIN64
3180
3180
static_cast <char *>(ptr), static_cast <int >(size),
3181
3181
#else
3182
3182
ptr, size,
@@ -3189,7 +3189,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
3189
3189
int flags) {
3190
3190
return handle_EINTR ([&]() {
3191
3191
return send (sock,
3192
- #ifdef _WIN32
3192
+ #ifdef _WIN64
3193
3193
static_cast <const char *>(ptr), static_cast <int >(size),
3194
3194
#else
3195
3195
ptr, size,
@@ -3199,7 +3199,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
3199
3199
}
3200
3200
3201
3201
inline int poll_wrapper (struct pollfd *fds, nfds_t nfds, int timeout) {
3202
- #ifdef _WIN32
3202
+ #ifdef _WIN64
3203
3203
return ::WSAPoll (fds, nfds, timeout);
3204
3204
#else
3205
3205
return ::poll (fds, nfds, timeout);
@@ -3409,7 +3409,7 @@ inline bool process_client_socket(
3409
3409
}
3410
3410
3411
3411
inline int shutdown_socket (socket_t sock) {
3412
- #ifdef _WIN32
3412
+ #ifdef _WIN64
3413
3413
return shutdown (sock, SD_BOTH);
3414
3414
#else
3415
3415
return shutdown (sock, SHUT_RDWR);
@@ -3444,7 +3444,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
3444
3444
return getaddrinfo (node, service, hints, res);
3445
3445
}
3446
3446
3447
- #ifdef _WIN32
3447
+ #ifdef _WIN64
3448
3448
// Windows-specific implementation using GetAddrInfoEx with overlapped I/O
3449
3449
OVERLAPPED overlapped = {0 };
3450
3450
HANDLE event = CreateEventW (nullptr , TRUE , FALSE , nullptr );
@@ -3777,7 +3777,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3777
3777
hints.ai_flags = socket_flags;
3778
3778
}
3779
3779
3780
- #if !defined(_WIN32 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3780
+ #if !defined(_WIN64 ) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3781
3781
if (hints.ai_family == AF_UNIX) {
3782
3782
const auto addrlen = host.length ();
3783
3783
if (addrlen > sizeof (sockaddr_un::sun_path)) { return INVALID_SOCKET; }
@@ -3801,14 +3801,14 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3801
3801
sizeof (addr) - sizeof (addr.sun_path ) + addrlen);
3802
3802
3803
3803
#ifndef SOCK_CLOEXEC
3804
- #ifndef _WIN32
3804
+ #ifndef _WIN64
3805
3805
fcntl (sock, F_SETFD, FD_CLOEXEC);
3806
3806
#endif
3807
3807
#endif
3808
3808
3809
3809
if (socket_options) { socket_options (sock); }
3810
3810
3811
- #ifdef _WIN32
3811
+ #ifdef _WIN64
3812
3812
// Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
3813
3813
// remove the option.
3814
3814
detail::set_socket_opt (sock, SOL_SOCKET, SO_REUSEADDR, 0 );
@@ -3837,7 +3837,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3837
3837
3838
3838
for (auto rp = result; rp; rp = rp->ai_next ) {
3839
3839
// Create a socket
3840
- #ifdef _WIN32
3840
+ #ifdef _WIN64
3841
3841
auto sock =
3842
3842
WSASocketW (rp->ai_family , rp->ai_socktype , rp->ai_protocol , nullptr , 0 ,
3843
3843
WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED);
@@ -3870,7 +3870,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3870
3870
#endif
3871
3871
if (sock == INVALID_SOCKET) { continue ; }
3872
3872
3873
- #if !defined _WIN32 && !defined SOCK_CLOEXEC
3873
+ #if !defined _WIN64 && !defined SOCK_CLOEXEC
3874
3874
if (fcntl (sock, F_SETFD, FD_CLOEXEC) == -1 ) {
3875
3875
close_socket (sock);
3876
3876
continue ;
@@ -3898,7 +3898,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3898
3898
}
3899
3899
3900
3900
inline void set_nonblocking (socket_t sock, bool nonblocking) {
3901
- #ifdef _WIN32
3901
+ #ifdef _WIN64
3902
3902
auto flags = nonblocking ? 1UL : 0UL ;
3903
3903
ioctlsocket (sock, FIONBIO, &flags);
3904
3904
#else
@@ -3909,7 +3909,7 @@ inline void set_nonblocking(socket_t sock, bool nonblocking) {
3909
3909
}
3910
3910
3911
3911
inline bool is_connection_error () {
3912
- #ifdef _WIN32
3912
+ #ifdef _WIN64
3913
3913
return WSAGetLastError () != WSAEWOULDBLOCK;
3914
3914
#else
3915
3915
return errno != EINPROGRESS;
@@ -3943,7 +3943,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
3943
3943
return ret;
3944
3944
}
3945
3945
3946
- #if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__
3946
+ #if !defined _WIN64 && !defined ANDROID && !defined _AIX && !defined __MVS__
3947
3947
#define USE_IF2IP
3948
3948
#endif
3949
3949
@@ -4082,7 +4082,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
4082
4082
4083
4083
if (!getpeername (sock, reinterpret_cast <struct sockaddr *>(&addr),
4084
4084
&addr_len)) {
4085
- #ifndef _WIN32
4085
+ #ifndef _WIN64
4086
4086
if (addr.ss_family == AF_UNIX) {
4087
4087
#if defined(__linux__)
4088
4088
struct ucred ucred;
@@ -6098,7 +6098,7 @@ inline bool is_ssl_peer_could_be_closed(SSL *ssl, socket_t sock) {
6098
6098
SSL_get_error (ssl, 0 ) == SSL_ERROR_ZERO_RETURN;
6099
6099
}
6100
6100
6101
- #ifdef _WIN32
6101
+ #ifdef _WIN64
6102
6102
// NOTE: This code came up with the following stackoverflow post:
6103
6103
// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store
6104
6104
inline bool load_system_certs_on_windows (X509_STORE *store) {
@@ -6214,10 +6214,10 @@ inline bool load_system_certs_on_macos(X509_STORE *store) {
6214
6214
6215
6215
return result;
6216
6216
}
6217
- #endif // _WIN32
6217
+ #endif // _WIN64
6218
6218
#endif // CPPHTTPLIB_OPENSSL_SUPPORT
6219
6219
6220
- #ifdef _WIN32
6220
+ #ifdef _WIN64
6221
6221
class WSInit {
6222
6222
public:
6223
6223
WSInit () {
@@ -6733,7 +6733,7 @@ inline bool SocketStream::wait_writable() const {
6733
6733
}
6734
6734
6735
6735
inline ssize_t SocketStream::read (char *ptr, size_t size) {
6736
- #ifdef _WIN32
6736
+ #ifdef _WIN64
6737
6737
size =
6738
6738
(std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
6739
6739
#else
@@ -6781,7 +6781,7 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
6781
6781
inline ssize_t SocketStream::write (const char *ptr, size_t size) {
6782
6782
if (!wait_writable ()) { return -1 ; }
6783
6783
6784
- #if defined(_WIN32 ) && !defined(_WIN64)
6784
+ #if defined(_WIN64 ) && !defined(_WIN64)
6785
6785
size =
6786
6786
(std::min)(size, static_cast <size_t >((std::numeric_limits<int >::max)()));
6787
6787
#endif
@@ -6944,7 +6944,7 @@ inline bool RegexMatcher::match(Request &request) const {
6944
6944
inline Server::Server ()
6945
6945
: new_task_queue (
6946
6946
[] { return new ThreadPool (CPPHTTPLIB_THREAD_POOL_COUNT); }) {
6947
- #ifndef _WIN32
6947
+ #ifndef _WIN64
6948
6948
signal (SIGPIPE, SIG_IGN);
6949
6949
#endif
6950
6950
}
@@ -7616,7 +7616,7 @@ inline bool Server::listen_internal() {
7616
7616
std::unique_ptr<TaskQueue> task_queue (new_task_queue ());
7617
7617
7618
7618
while (svr_sock_ != INVALID_SOCKET) {
7619
- #ifndef _WIN32
7619
+ #ifndef _WIN64
7620
7620
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0 ) {
7621
7621
#endif
7622
7622
auto val = detail::select_read (svr_sock_, idle_interval_sec_,
@@ -7625,11 +7625,11 @@ inline bool Server::listen_internal() {
7625
7625
task_queue->on_idle ();
7626
7626
continue ;
7627
7627
}
7628
- #ifndef _WIN32
7628
+ #ifndef _WIN64
7629
7629
}
7630
7630
#endif
7631
7631
7632
- #if defined _WIN32
7632
+ #if defined _WIN64
7633
7633
// sockets connected via WASAccept inherit flags NO_HANDLE_INHERIT,
7634
7634
// OVERLAPPED
7635
7635
socket_t sock = WSAAccept (svr_sock_, nullptr , nullptr , nullptr , 0 );
@@ -10114,7 +10114,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
10114
10114
if (ret < 0 ) {
10115
10115
auto err = SSL_get_error (ssl_, ret);
10116
10116
auto n = 1000 ;
10117
- #ifdef _WIN32
10117
+ #ifdef _WIN64
10118
10118
while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
10119
10119
(err == SSL_ERROR_SYSCALL &&
10120
10120
WSAGetLastError () == WSAETIMEDOUT))) {
@@ -10149,7 +10149,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
10149
10149
if (ret < 0 ) {
10150
10150
auto err = SSL_get_error (ssl_, ret);
10151
10151
auto n = 1000 ;
10152
- #ifdef _WIN32
10152
+ #ifdef _WIN64
10153
10153
while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
10154
10154
(err == SSL_ERROR_SYSCALL &&
10155
10155
WSAGetLastError () == WSAETIMEDOUT))) {
@@ -10541,13 +10541,13 @@ inline bool SSLClient::load_certs() {
10541
10541
}
10542
10542
} else {
10543
10543
auto loaded = false ;
10544
- #ifdef _WIN32
10544
+ #ifdef _WIN64
10545
10545
loaded =
10546
10546
detail::load_system_certs_on_windows (SSL_CTX_get_cert_store (ctx_));
10547
10547
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \
10548
10548
defined (TARGET_OS_OSX)
10549
10549
loaded = detail::load_system_certs_on_macos (SSL_CTX_get_cert_store (ctx_));
10550
- #endif // _WIN32
10550
+ #endif // _WIN64
10551
10551
if (!loaded) { SSL_CTX_set_default_verify_paths (ctx_); }
10552
10552
}
10553
10553
});
0 commit comments