Skip to content

Commit 7654cf3

Browse files
committed
Fix #2175
1 parent 4ff7a1c commit 7654cf3

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

httplib.h

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
#endif
9191

9292
#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND
93-
#ifdef _WIN32
93+
#ifdef _WIN64
9494
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 1000
9595
#else
9696
#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0
@@ -176,7 +176,7 @@
176176
* Headers
177177
*/
178178

179-
#ifdef _WIN32
179+
#ifdef _WIN64
180180
#ifndef _CRT_SECURE_NO_WARNINGS
181181
#define _CRT_SECURE_NO_WARNINGS
182182
#endif //_CRT_SECURE_NO_WARNINGS
@@ -227,7 +227,7 @@ using nfds_t = unsigned long;
227227
using socket_t = SOCKET;
228228
using socklen_t = int;
229229

230-
#else // not _WIN32
230+
#else // not _WIN64
231231

232232
#include <arpa/inet.h>
233233
#if !defined(_AIX) && !defined(__MVS__)
@@ -258,7 +258,7 @@ using socket_t = int;
258258
#ifndef INVALID_SOCKET
259259
#define INVALID_SOCKET (-1)
260260
#endif
261-
#endif //_WIN32
261+
#endif //_WIN64
262262

263263
#if defined(__APPLE__)
264264
#include <TargetConditionals.h>
@@ -303,7 +303,7 @@ using socket_t = int;
303303
// CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN
304304

305305
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
306-
#ifdef _WIN32
306+
#ifdef _WIN64
307307
#include <wincrypt.h>
308308

309309
// these are defined in wincrypt.h and it breaks compilation if BoringSSL is
@@ -316,7 +316,7 @@ using socket_t = int;
316316
#ifdef _MSC_VER
317317
#pragma comment(lib, "crypt32.lib")
318318
#endif
319-
#endif // _WIN32
319+
#endif // _WIN64
320320

321321
#if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
322322
#if TARGET_OS_OSX
@@ -329,7 +329,7 @@ using socket_t = int;
329329
#include <openssl/ssl.h>
330330
#include <openssl/x509v3.h>
331331

332-
#if defined(_WIN32) && defined(OPENSSL_USE_APPLINK)
332+
#if defined(_WIN64) && defined(OPENSSL_USE_APPLINK)
333333
#include <openssl/applink.c>
334334
#endif
335335

@@ -2030,7 +2030,7 @@ namespace detail {
20302030
inline bool set_socket_opt_impl(socket_t sock, int level, int optname,
20312031
const void *optval, socklen_t optlen) {
20322032
return setsockopt(sock, level, optname,
2033-
#ifdef _WIN32
2033+
#ifdef _WIN64
20342034
reinterpret_cast<const char *>(optval),
20352035
#else
20362036
optval,
@@ -2044,7 +2044,7 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
20442044

20452045
inline bool set_socket_opt_time(socket_t sock, int level, int optname,
20462046
time_t sec, time_t usec) {
2047-
#ifdef _WIN32
2047+
#ifdef _WIN64
20482048
auto timeout = static_cast<uint32_t>(sec * 1000 + usec / 1000);
20492049
#else
20502050
timeval timeout;
@@ -2297,7 +2297,7 @@ make_basic_authentication_header(const std::string &username,
22972297

22982298
namespace detail {
22992299

2300-
#if defined(_WIN32)
2300+
#if defined(_WIN64)
23012301
inline std::wstring u8string_to_wstring(const char *s) {
23022302
std::wstring ws;
23032303
auto len = static_cast<int>(strlen(s));
@@ -2319,7 +2319,7 @@ struct FileStat {
23192319
bool is_dir() const;
23202320

23212321
private:
2322-
#if defined(_WIN32)
2322+
#if defined(_WIN64)
23232323
struct _stat st_;
23242324
#else
23252325
struct stat st_;
@@ -2562,7 +2562,7 @@ class mmap {
25622562
const char *data() const;
25632563

25642564
private:
2565-
#if defined(_WIN32)
2565+
#if defined(_WIN64)
25662566
HANDLE hFile_ = NULL;
25672567
HANDLE hMapping_ = NULL;
25682568
#else
@@ -2783,7 +2783,7 @@ inline bool is_valid_path(const std::string &path) {
27832783
}
27842784

27852785
inline FileStat::FileStat(const std::string &path) {
2786-
#if defined(_WIN32)
2786+
#if defined(_WIN64)
27872787
auto wpath = u8string_to_wstring(path.c_str());
27882788
ret_ = _wstat(wpath.c_str(), &st_);
27892789
#else
@@ -3032,7 +3032,7 @@ inline mmap::~mmap() { close(); }
30323032
inline bool mmap::open(const char *path) {
30333033
close();
30343034

3035-
#if defined(_WIN32)
3035+
#if defined(_WIN64)
30363036
auto wpath = u8string_to_wstring(path);
30373037
if (wpath.empty()) { return false; }
30383038

@@ -3122,7 +3122,7 @@ inline const char *mmap::data() const {
31223122
}
31233123

31243124
inline void mmap::close() {
3125-
#if defined(_WIN32)
3125+
#if defined(_WIN64)
31263126
if (addr_) {
31273127
::UnmapViewOfFile(addr_);
31283128
addr_ = nullptr;
@@ -3153,7 +3153,7 @@ inline void mmap::close() {
31533153
size_ = 0;
31543154
}
31553155
inline int close_socket(socket_t sock) {
3156-
#ifdef _WIN32
3156+
#ifdef _WIN64
31573157
return closesocket(sock);
31583158
#else
31593159
return close(sock);
@@ -3176,7 +3176,7 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
31763176
inline ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags) {
31773177
return handle_EINTR([&]() {
31783178
return recv(sock,
3179-
#ifdef _WIN32
3179+
#ifdef _WIN64
31803180
static_cast<char *>(ptr), static_cast<int>(size),
31813181
#else
31823182
ptr, size,
@@ -3189,7 +3189,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
31893189
int flags) {
31903190
return handle_EINTR([&]() {
31913191
return send(sock,
3192-
#ifdef _WIN32
3192+
#ifdef _WIN64
31933193
static_cast<const char *>(ptr), static_cast<int>(size),
31943194
#else
31953195
ptr, size,
@@ -3199,7 +3199,7 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
31993199
}
32003200

32013201
inline int poll_wrapper(struct pollfd *fds, nfds_t nfds, int timeout) {
3202-
#ifdef _WIN32
3202+
#ifdef _WIN64
32033203
return ::WSAPoll(fds, nfds, timeout);
32043204
#else
32053205
return ::poll(fds, nfds, timeout);
@@ -3409,7 +3409,7 @@ inline bool process_client_socket(
34093409
}
34103410

34113411
inline int shutdown_socket(socket_t sock) {
3412-
#ifdef _WIN32
3412+
#ifdef _WIN64
34133413
return shutdown(sock, SD_BOTH);
34143414
#else
34153415
return shutdown(sock, SHUT_RDWR);
@@ -3444,7 +3444,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service,
34443444
return getaddrinfo(node, service, hints, res);
34453445
}
34463446

3447-
#ifdef _WIN32
3447+
#ifdef _WIN64
34483448
// Windows-specific implementation using GetAddrInfoEx with overlapped I/O
34493449
OVERLAPPED overlapped = {0};
34503450
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,
37773777
hints.ai_flags = socket_flags;
37783778
}
37793779

3780-
#if !defined(_WIN32) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
3780+
#if !defined(_WIN64) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
37813781
if (hints.ai_family == AF_UNIX) {
37823782
const auto addrlen = host.length();
37833783
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,
38013801
sizeof(addr) - sizeof(addr.sun_path) + addrlen);
38023802

38033803
#ifndef SOCK_CLOEXEC
3804-
#ifndef _WIN32
3804+
#ifndef _WIN64
38053805
fcntl(sock, F_SETFD, FD_CLOEXEC);
38063806
#endif
38073807
#endif
38083808

38093809
if (socket_options) { socket_options(sock); }
38103810

3811-
#ifdef _WIN32
3811+
#ifdef _WIN64
38123812
// Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so
38133813
// remove the option.
38143814
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,
38373837

38383838
for (auto rp = result; rp; rp = rp->ai_next) {
38393839
// Create a socket
3840-
#ifdef _WIN32
3840+
#ifdef _WIN64
38413841
auto sock =
38423842
WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0,
38433843
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,
38703870
#endif
38713871
if (sock == INVALID_SOCKET) { continue; }
38723872

3873-
#if !defined _WIN32 && !defined SOCK_CLOEXEC
3873+
#if !defined _WIN64 && !defined SOCK_CLOEXEC
38743874
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) {
38753875
close_socket(sock);
38763876
continue;
@@ -3898,7 +3898,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
38983898
}
38993899

39003900
inline void set_nonblocking(socket_t sock, bool nonblocking) {
3901-
#ifdef _WIN32
3901+
#ifdef _WIN64
39023902
auto flags = nonblocking ? 1UL : 0UL;
39033903
ioctlsocket(sock, FIONBIO, &flags);
39043904
#else
@@ -3909,7 +3909,7 @@ inline void set_nonblocking(socket_t sock, bool nonblocking) {
39093909
}
39103910

39113911
inline bool is_connection_error() {
3912-
#ifdef _WIN32
3912+
#ifdef _WIN64
39133913
return WSAGetLastError() != WSAEWOULDBLOCK;
39143914
#else
39153915
return errno != EINPROGRESS;
@@ -3943,7 +3943,7 @@ inline bool bind_ip_address(socket_t sock, const std::string &host) {
39433943
return ret;
39443944
}
39453945

3946-
#if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__
3946+
#if !defined _WIN64 && !defined ANDROID && !defined _AIX && !defined __MVS__
39473947
#define USE_IF2IP
39483948
#endif
39493949

@@ -4082,7 +4082,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
40824082

40834083
if (!getpeername(sock, reinterpret_cast<struct sockaddr *>(&addr),
40844084
&addr_len)) {
4085-
#ifndef _WIN32
4085+
#ifndef _WIN64
40864086
if (addr.ss_family == AF_UNIX) {
40874087
#if defined(__linux__)
40884088
struct ucred ucred;
@@ -6098,7 +6098,7 @@ inline bool is_ssl_peer_could_be_closed(SSL *ssl, socket_t sock) {
60986098
SSL_get_error(ssl, 0) == SSL_ERROR_ZERO_RETURN;
60996099
}
61006100

6101-
#ifdef _WIN32
6101+
#ifdef _WIN64
61026102
// NOTE: This code came up with the following stackoverflow post:
61036103
// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store
61046104
inline bool load_system_certs_on_windows(X509_STORE *store) {
@@ -6214,10 +6214,10 @@ inline bool load_system_certs_on_macos(X509_STORE *store) {
62146214

62156215
return result;
62166216
}
6217-
#endif // _WIN32
6217+
#endif // _WIN64
62186218
#endif // CPPHTTPLIB_OPENSSL_SUPPORT
62196219

6220-
#ifdef _WIN32
6220+
#ifdef _WIN64
62216221
class WSInit {
62226222
public:
62236223
WSInit() {
@@ -6733,7 +6733,7 @@ inline bool SocketStream::wait_writable() const {
67336733
}
67346734

67356735
inline ssize_t SocketStream::read(char *ptr, size_t size) {
6736-
#ifdef _WIN32
6736+
#ifdef _WIN64
67376737
size =
67386738
(std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
67396739
#else
@@ -6781,7 +6781,7 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
67816781
inline ssize_t SocketStream::write(const char *ptr, size_t size) {
67826782
if (!wait_writable()) { return -1; }
67836783

6784-
#if defined(_WIN32) && !defined(_WIN64)
6784+
#if defined(_WIN64) && !defined(_WIN64)
67856785
size =
67866786
(std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
67876787
#endif
@@ -6944,7 +6944,7 @@ inline bool RegexMatcher::match(Request &request) const {
69446944
inline Server::Server()
69456945
: new_task_queue(
69466946
[] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }) {
6947-
#ifndef _WIN32
6947+
#ifndef _WIN64
69486948
signal(SIGPIPE, SIG_IGN);
69496949
#endif
69506950
}
@@ -7616,7 +7616,7 @@ inline bool Server::listen_internal() {
76167616
std::unique_ptr<TaskQueue> task_queue(new_task_queue());
76177617

76187618
while (svr_sock_ != INVALID_SOCKET) {
7619-
#ifndef _WIN32
7619+
#ifndef _WIN64
76207620
if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) {
76217621
#endif
76227622
auto val = detail::select_read(svr_sock_, idle_interval_sec_,
@@ -7625,11 +7625,11 @@ inline bool Server::listen_internal() {
76257625
task_queue->on_idle();
76267626
continue;
76277627
}
7628-
#ifndef _WIN32
7628+
#ifndef _WIN64
76297629
}
76307630
#endif
76317631

7632-
#if defined _WIN32
7632+
#if defined _WIN64
76337633
// sockets connected via WASAccept inherit flags NO_HANDLE_INHERIT,
76347634
// OVERLAPPED
76357635
socket_t sock = WSAAccept(svr_sock_, nullptr, nullptr, nullptr, 0);
@@ -10114,7 +10114,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
1011410114
if (ret < 0) {
1011510115
auto err = SSL_get_error(ssl_, ret);
1011610116
auto n = 1000;
10117-
#ifdef _WIN32
10117+
#ifdef _WIN64
1011810118
while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
1011910119
(err == SSL_ERROR_SYSCALL &&
1012010120
WSAGetLastError() == WSAETIMEDOUT))) {
@@ -10149,7 +10149,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
1014910149
if (ret < 0) {
1015010150
auto err = SSL_get_error(ssl_, ret);
1015110151
auto n = 1000;
10152-
#ifdef _WIN32
10152+
#ifdef _WIN64
1015310153
while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
1015410154
(err == SSL_ERROR_SYSCALL &&
1015510155
WSAGetLastError() == WSAETIMEDOUT))) {
@@ -10541,13 +10541,13 @@ inline bool SSLClient::load_certs() {
1054110541
}
1054210542
} else {
1054310543
auto loaded = false;
10544-
#ifdef _WIN32
10544+
#ifdef _WIN64
1054510545
loaded =
1054610546
detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_));
1054710547
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \
1054810548
defined(TARGET_OS_OSX)
1054910549
loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_));
10550-
#endif // _WIN32
10550+
#endif // _WIN64
1055110551
if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); }
1055210552
}
1055310553
});

0 commit comments

Comments
 (0)