@@ -194,9 +194,7 @@ using ssize_t = long;
194194
195195using socket_t = SOCKET;
196196using socklen_t = int ;
197- #ifdef CPPHTTPLIB_USE_POLL
198197#define poll (fds, nfds, timeout ) WSAPoll(fds, nfds, timeout)
199- #endif
200198
201199#else // not _WIN32
202200
@@ -216,16 +214,11 @@ using socklen_t = int;
216214#ifdef __linux__
217215#include < resolv.h>
218216#endif
217+ #include < csignal>
219218#include < netinet/tcp.h>
220- #ifdef CPPHTTPLIB_USE_POLL
221219#include < poll.h>
222- #endif
223- #include < csignal>
224220#include < pthread.h>
225221#include < sys/mman.h>
226- #ifndef __VMS
227- #include < sys/select.h>
228- #endif
229222#include < sys/socket.h>
230223#include < sys/un.h>
231224#include < unistd.h>
@@ -3259,33 +3252,13 @@ inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
32593252
32603253template <bool Read>
32613254inline ssize_t select_impl (socket_t sock, time_t sec, time_t usec) {
3262- #ifdef CPPHTTPLIB_USE_POLL
32633255 struct pollfd pfd;
32643256 pfd.fd = sock;
32653257 pfd.events = (Read ? POLLIN : POLLOUT);
32663258
32673259 auto timeout = static_cast <int >(sec * 1000 + usec / 1000 );
32683260
32693261 return handle_EINTR ([&]() { return poll (&pfd, 1 , timeout); });
3270- #else
3271- #ifndef _WIN32
3272- if (sock >= FD_SETSIZE) { return -1 ; }
3273- #endif
3274-
3275- fd_set fds, *rfds, *wfds;
3276- FD_ZERO (&fds);
3277- FD_SET (sock, &fds);
3278- rfds = (Read ? &fds : nullptr );
3279- wfds = (Read ? nullptr : &fds);
3280-
3281- timeval tv;
3282- tv.tv_sec = static_cast <long >(sec);
3283- tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
3284-
3285- return handle_EINTR ([&]() {
3286- return select (static_cast <int >(sock + 1 ), rfds, wfds, nullptr , &tv);
3287- });
3288- #endif
32893262}
32903263
32913264inline ssize_t select_read (socket_t sock, time_t sec, time_t usec) {
@@ -3298,7 +3271,6 @@ inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) {
32983271
32993272inline Error wait_until_socket_is_ready (socket_t sock, time_t sec,
33003273 time_t usec) {
3301- #ifdef CPPHTTPLIB_USE_POLL
33023274 struct pollfd pfd_read;
33033275 pfd_read.fd = sock;
33043276 pfd_read.events = POLLIN | POLLOUT;
@@ -3319,38 +3291,6 @@ inline Error wait_until_socket_is_ready(socket_t sock, time_t sec,
33193291 }
33203292
33213293 return Error::Connection;
3322- #else
3323- #ifndef _WIN32
3324- if (sock >= FD_SETSIZE) { return Error::Connection; }
3325- #endif
3326-
3327- fd_set fdsr;
3328- FD_ZERO (&fdsr);
3329- FD_SET (sock, &fdsr);
3330-
3331- auto fdsw = fdsr;
3332- auto fdse = fdsr;
3333-
3334- timeval tv;
3335- tv.tv_sec = static_cast <long >(sec);
3336- tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
3337-
3338- auto ret = handle_EINTR ([&]() {
3339- return select (static_cast <int >(sock + 1 ), &fdsr, &fdsw, &fdse, &tv);
3340- });
3341-
3342- if (ret == 0 ) { return Error::ConnectionTimeout; }
3343-
3344- if (ret > 0 && (FD_ISSET (sock, &fdsr) || FD_ISSET (sock, &fdsw))) {
3345- auto error = 0 ;
3346- socklen_t len = sizeof (error);
3347- auto res = getsockopt (sock, SOL_SOCKET, SO_ERROR,
3348- reinterpret_cast <char *>(&error), &len);
3349- auto successful = res >= 0 && !error;
3350- return successful ? Error::Success : Error::Connection;
3351- }
3352- return Error::Connection;
3353- #endif
33543294}
33553295
33563296inline bool is_socket_alive (socket_t sock) {
@@ -7196,20 +7136,6 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
71967136 res.version = " HTTP/1.1" ;
71977137 res.headers = default_headers_;
71987138
7199- #ifdef _WIN32
7200- // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL).
7201- #else
7202- #ifndef CPPHTTPLIB_USE_POLL
7203- // Socket file descriptor exceeded FD_SETSIZE...
7204- if (strm.socket () >= FD_SETSIZE) {
7205- Headers dummy;
7206- detail::read_headers (strm, dummy);
7207- res.status = StatusCode::InternalServerError_500;
7208- return write_response (strm, close_connection, req, res);
7209- }
7210- #endif
7211- #endif
7212-
72137139 // Request line and headers
72147140 if (!parse_request_line (line_reader.ptr (), req) ||
72157141 !detail::read_headers (strm, req.headers )) {
@@ -10440,7 +10366,7 @@ inline SSL_CTX *Client::ssl_context() const {
1044010366
1044110367} // namespace httplib
1044210368
10443- #if defined( _WIN32) && defined(CPPHTTPLIB_USE_POLL)
10369+ #ifdef _WIN32
1044410370#undef poll
1044510371#endif
1044610372
0 commit comments