145
145
#define CPPHTTPLIB_LISTEN_BACKLOG 5
146
146
#endif
147
147
148
- #if !defined(CPPHTTPLIB_USE_POLL) && !defined(CPPHTTPLIB_USE_SELECT)
149
- #define CPPHTTPLIB_USE_POLL
150
- #elif defined(CPPHTTPLIB_USE_POLL) && defined(CPPHTTPLIB_USE_SELECT)
151
- #error "CPPHTTPLIB_USE_POLL and CPPHTTPLIB_USE_SELECT are mutually exclusive"
152
- #endif
153
-
154
148
/*
155
149
* Headers
156
150
*/
@@ -200,9 +194,7 @@ using ssize_t = long;
200
194
201
195
using socket_t = SOCKET;
202
196
using socklen_t = int ;
203
- #ifdef CPPHTTPLIB_USE_POLL
204
197
#define poll (fds, nfds, timeout ) WSAPoll(fds, nfds, timeout)
205
- #endif
206
198
207
199
#else // not _WIN32
208
200
@@ -222,16 +214,11 @@ using socklen_t = int;
222
214
#ifdef __linux__
223
215
#include < resolv.h>
224
216
#endif
217
+ #include < csignal>
225
218
#include < netinet/tcp.h>
226
- #ifdef CPPHTTPLIB_USE_POLL
227
219
#include < poll.h>
228
- #endif
229
- #include < csignal>
230
220
#include < pthread.h>
231
221
#include < sys/mman.h>
232
- #ifndef __VMS
233
- #include < sys/select.h>
234
- #endif
235
222
#include < sys/socket.h>
236
223
#include < sys/un.h>
237
224
#include < unistd.h>
@@ -3267,33 +3254,13 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
3267
3254
3268
3255
template <bool Read>
3269
3256
inline ssize_t select_impl (socket_t sock, time_t sec, time_t usec) {
3270
- #ifdef CPPHTTPLIB_USE_POLL
3271
3257
struct pollfd pfd;
3272
3258
pfd.fd = sock;
3273
3259
pfd.events = (Read ? POLLIN : POLLOUT);
3274
3260
3275
3261
auto timeout = static_cast <int >(sec * 1000 + usec / 1000 );
3276
3262
3277
3263
return handle_EINTR ([&]() { return poll (&pfd, 1 , timeout); });
3278
- #else
3279
- #ifndef _WIN32
3280
- if (sock >= FD_SETSIZE) { return -1 ; }
3281
- #endif
3282
-
3283
- fd_set fds, *rfds, *wfds;
3284
- FD_ZERO (&fds);
3285
- FD_SET (sock, &fds);
3286
- rfds = (Read ? &fds : nullptr );
3287
- wfds = (Read ? nullptr : &fds);
3288
-
3289
- timeval tv;
3290
- tv.tv_sec = static_cast <long >(sec);
3291
- tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
3292
-
3293
- return handle_EINTR ([&]() {
3294
- return select (static_cast <int >(sock + 1 ), rfds, wfds, nullptr , &tv);
3295
- });
3296
- #endif
3297
3264
}
3298
3265
3299
3266
inline ssize_t select_read (socket_t sock, time_t sec, time_t usec) {
@@ -3306,7 +3273,6 @@ inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) {
3306
3273
3307
3274
inline Error wait_until_socket_is_ready (socket_t sock, time_t sec,
3308
3275
time_t usec) {
3309
- #ifdef CPPHTTPLIB_USE_POLL
3310
3276
struct pollfd pfd_read;
3311
3277
pfd_read.fd = sock;
3312
3278
pfd_read.events = POLLIN | POLLOUT;
@@ -3327,38 +3293,6 @@ inline Error wait_until_socket_is_ready(socket_t sock, time_t sec,
3327
3293
}
3328
3294
3329
3295
return Error::Connection;
3330
- #else
3331
- #ifndef _WIN32
3332
- if (sock >= FD_SETSIZE) { return Error::Connection; }
3333
- #endif
3334
-
3335
- fd_set fdsr;
3336
- FD_ZERO (&fdsr);
3337
- FD_SET (sock, &fdsr);
3338
-
3339
- auto fdsw = fdsr;
3340
- auto fdse = fdsr;
3341
-
3342
- timeval tv;
3343
- tv.tv_sec = static_cast <long >(sec);
3344
- tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
3345
-
3346
- auto ret = handle_EINTR ([&]() {
3347
- return select (static_cast <int >(sock + 1 ), &fdsr, &fdsw, &fdse, &tv);
3348
- });
3349
-
3350
- if (ret == 0 ) { return Error::ConnectionTimeout; }
3351
-
3352
- if (ret > 0 && (FD_ISSET (sock, &fdsr) || FD_ISSET (sock, &fdsw))) {
3353
- auto error = 0 ;
3354
- socklen_t len = sizeof (error);
3355
- auto res = getsockopt (sock, SOL_SOCKET, SO_ERROR,
3356
- reinterpret_cast <char *>(&error), &len);
3357
- auto successful = res >= 0 && !error;
3358
- return successful ? Error::Success : Error::Connection;
3359
- }
3360
- return Error::Connection;
3361
- #endif
3362
3296
}
3363
3297
3364
3298
inline bool is_socket_alive (socket_t sock) {
@@ -7208,20 +7142,6 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
7208
7142
res.version = " HTTP/1.1" ;
7209
7143
res.headers = default_headers_;
7210
7144
7211
- #ifdef _WIN32
7212
- // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL).
7213
- #else
7214
- #ifndef CPPHTTPLIB_USE_POLL
7215
- // Socket file descriptor exceeded FD_SETSIZE...
7216
- if (strm.socket () >= FD_SETSIZE) {
7217
- Headers dummy;
7218
- detail::read_headers (strm, dummy);
7219
- res.status = StatusCode::InternalServerError_500;
7220
- return write_response (strm, close_connection, req, res);
7221
- }
7222
- #endif
7223
- #endif
7224
-
7225
7145
// Request line and headers
7226
7146
if (!parse_request_line (line_reader.ptr (), req) ||
7227
7147
!detail::read_headers (strm, req.headers )) {
@@ -10456,7 +10376,7 @@ inline SSL_CTX *Client::ssl_context() const {
10456
10376
10457
10377
} // namespace httplib
10458
10378
10459
- #if defined( _WIN32) && defined(CPPHTTPLIB_USE_POLL)
10379
+ #ifdef _WIN32
10460
10380
#undef poll
10461
10381
#endif
10462
10382
0 commit comments