Skip to content

Commit 478addd

Browse files
[HttpClient][Curl] Use poll api to avoid select 1024 FD hard limit (#1426)
1 parent 2954864 commit 478addd

1 file changed

Lines changed: 7 additions & 22 deletions

File tree

lib/http/HttpClient_Curl.hpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <future>
2424
#include <atomic>
2525

26+
#include <poll.h>
2627
#include <curl/curl.h>
2728

2829
#include <unistd.h>
@@ -462,28 +463,12 @@ class CurlHttpOperation {
462463
*/
463464
static int WaitOnSocket(curl_socket_t sockfd, int for_recv, long timeout_ms)
464465
{
465-
struct timeval tv;
466-
fd_set infd, outfd, errfd;
467-
int res;
468-
469-
tv.tv_sec = timeout_ms / 1000;
470-
tv.tv_usec = (timeout_ms % 1000) * 1000;
471-
472-
FD_ZERO(&infd);
473-
FD_ZERO(&outfd);
474-
FD_ZERO(&errfd);
475-
476-
FD_SET(sockfd, &errfd); /* always check for error */
477-
478-
if(for_recv) {
479-
FD_SET(sockfd, &infd);
480-
} else {
481-
FD_SET(sockfd, &outfd);
482-
}
483-
484-
/* select() returns the number of signalled sockets or -1 */
485-
res = select((int)sockfd + 1, &infd, &outfd, &errfd, &tv);
486-
return res;
466+
struct pollfd pfd;
467+
pfd.fd = sockfd;
468+
pfd.events = for_recv ? POLLIN : POLLOUT;
469+
// Cap timeout to max int value to avoid overflow in poll()
470+
auto timeout = std::min(timeout_ms, static_cast<long>(std::numeric_limits<int>::max()));
471+
return poll(&pfd, 1, static_cast<int>(timeout));
487472
}
488473

489474
// Raw response buffer

0 commit comments

Comments
 (0)