From 8333340e2cdf370d9c6ac4020e5fcaa1b2ece1da Mon Sep 17 00:00:00 2001 From: yhirose Date: Mon, 27 Apr 2020 12:36:39 -0400 Subject: [PATCH] Chagned to use inline function instead of macro --- httplib.h | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/httplib.h b/httplib.h index e1401aa..03ef11a 100644 --- a/httplib.h +++ b/httplib.h @@ -172,18 +172,6 @@ inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) { #endif #endif -#define HANDLE_EINTR(method, ...) \ - ({int res; \ - while (true) { \ - res = method(__VA_ARGS__); \ - if (res < 0 && errno == EINTR) { \ - continue; \ - } else { \ - break; \ - } \ - } \ - res;}) - #ifdef CPPHTTPLIB_ZLIB_SUPPORT #include #endif @@ -1266,7 +1254,7 @@ inline bool wait_until_socket_is_ready(socket_t sock, time_t sec, time_t usec) { if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) { int error = 0; socklen_t len = sizeof(error); - int res = getsockopt(sock, SOL_SOCKET, SO_ERROR, + auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error), &len); return res >= 0 && !error; } @@ -2627,6 +2615,21 @@ inline std::string SHA_512(const std::string &s) { } #endif +template +inline ssize_t handle_EINTR(T fn) { + ssize_t res = false; + while (true) { + res = fn(); + if (res < 0 && errno == EINTR) { + continue; + } + break; + } + return res; +} + +#define HANDLE_EINTR(method, ...) (handle_EINTR([&]() { return method(__VA_ARGS__); })) + #ifdef _WIN32 class WSInit { public: @@ -5106,6 +5109,12 @@ inline std::shared_ptr Get(const char *url) { } // namespace url +namespace detail { + +#undef HANDLE_EINTR + +} // namespace detail + // ---------------------------------------------------------------------------- } // namespace httplib