@@ -1634,9 +1634,6 @@ template <typename T> inline ssize_t handle_EINTR(T fn) {
16341634 return res;
16351635}
16361636
1637- #define HANDLE_EINTR (method, ...) \
1638- (handle_EINTR([&]() { return method (__VA_ARGS__); }))
1639-
16401637inline ssize_t select_read (socket_t sock, time_t sec, time_t usec) {
16411638#ifdef CPPHTTPLIB_USE_POLL
16421639 struct pollfd pfd_read;
@@ -1645,7 +1642,7 @@ inline ssize_t select_read(socket_t sock, time_t sec, time_t usec) {
16451642
16461643 auto timeout = static_cast <int >(sec * 1000 + usec / 1000 );
16471644
1648- return HANDLE_EINTR (poll, &pfd_read, 1 , timeout);
1645+ return handle_EINTR ([&]() { return poll ( &pfd_read, 1 , timeout); } );
16491646#else
16501647 fd_set fds;
16511648 FD_ZERO (&fds);
@@ -1655,8 +1652,9 @@ inline ssize_t select_read(socket_t sock, time_t sec, time_t usec) {
16551652 tv.tv_sec = static_cast <long >(sec);
16561653 tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
16571654
1658- return HANDLE_EINTR (select, static_cast <int >(sock + 1 ), &fds, nullptr ,
1659- nullptr , &tv);
1655+ return handle_EINTR ([&]() {
1656+ return select (static_cast <int >(sock + 1 ), &fds, nullptr , nullptr , &tv);
1657+ });
16601658#endif
16611659}
16621660
@@ -1668,7 +1666,7 @@ inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) {
16681666
16691667 auto timeout = static_cast <int >(sec * 1000 + usec / 1000 );
16701668
1671- return HANDLE_EINTR (poll, &pfd_read, 1 , timeout);
1669+ return handle_EINTR ([&]() { return poll ( &pfd_read, 1 , timeout); } );
16721670#else
16731671 fd_set fds;
16741672 FD_ZERO (&fds);
@@ -1678,8 +1676,9 @@ inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) {
16781676 tv.tv_sec = static_cast <long >(sec);
16791677 tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
16801678
1681- return HANDLE_EINTR (select, static_cast <int >(sock + 1 ), nullptr , &fds,
1682- nullptr , &tv);
1679+ return handle_EINTR ([&]() {
1680+ return select (static_cast <int >(sock + 1 ), nullptr , &fds, nullptr , &tv);
1681+ });
16831682#endif
16841683}
16851684
@@ -1691,7 +1690,8 @@ inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) {
16911690
16921691 auto timeout = static_cast <int >(sec * 1000 + usec / 1000 );
16931692
1694- auto poll_res = HANDLE_EINTR (poll, &pfd_read, 1 , timeout);
1693+ auto poll_res = handle_EINTR ([&]() { return poll (&pfd_read, 1 , timeout); });
1694+
16951695 if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) {
16961696 int error = 0 ;
16971697 socklen_t len = sizeof (error);
@@ -1712,9 +1712,11 @@ inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) {
17121712 tv.tv_sec = static_cast <long >(sec);
17131713 tv.tv_usec = static_cast <decltype (tv.tv_usec )>(usec);
17141714
1715- if (HANDLE_EINTR (select, static_cast <int >(sock + 1 ), &fdsr, &fdsw, &fdse,
1716- &tv) > 0 &&
1717- (FD_ISSET (sock, &fdsr) || FD_ISSET (sock, &fdsw))) {
1715+ auto ret = handle_EINTR ([&]() {
1716+ return select (static_cast <int >(sock + 1 ), &fdsr, &fdsw, &fdse, &tv);
1717+ });
1718+
1719+ if (ret > 0 && (FD_ISSET (sock, &fdsr) || FD_ISSET (sock, &fdsw))) {
17181720 int error = 0 ;
17191721 socklen_t len = sizeof (error);
17201722 return getsockopt (sock, SOL_SOCKET, SO_ERROR,
@@ -2404,7 +2406,8 @@ inline bool is_chunked_transfer_encoding(const Headers &headers) {
24042406
24052407template <typename T>
24062408bool read_content (Stream &strm, T &x, size_t payload_max_length, int &status,
2407- Progress progress, ContentReceiver receiver, bool decompress) {
2409+ Progress progress, ContentReceiver receiver,
2410+ bool decompress) {
24082411
24092412 ContentReceiver out = [&](const char *buf, size_t n) {
24102413 return receiver (buf, n);
@@ -5583,12 +5586,6 @@ inline bool SSLClient::check_host_name(const char *pattern,
55835586}
55845587#endif
55855588
5586- namespace detail {
5587-
5588- #undef HANDLE_EINTR
5589-
5590- } // namespace detail
5591-
55925589// ----------------------------------------------------------------------------
55935590
55945591} // namespace httplib
0 commit comments