cURL / Mailing Lists / curl-library / Single Mail


Re: how to use poll with libcurl

From: Daniel Stenberg <>
Date: Fri, 15 Mar 2013 11:28:58 +0100 (CET)

On Thu, 14 Mar 2013, jianqiu lv wrote:

> Recently I meet a problem the when using select after muti_curl_fdset, the
> maxfd is over 1024 in my process, and it is necessary to have such a value.

maxfd over FD_SETSIZE is indeed a problem in the select()-using parts of the

> I search in libcurl's example(
> , they have an example for how to use libevent with
> curl_multi_socket_action. I am not familiar with libevent nor have the plan
> to use libevent, since the socket fd in my process is not too much (less
> than 50,using poll which is O(n) is almost the same with using epoll O(1)),
> most all the fds are local files.

In the curl project we decided early on to provide a select() oriented API
since select() was then (and is still) the most widely available API for this
kind of operation. Later on we added the socket_action API which allows the
application to wait for sockets using any API at all that knows about
sockets/file descriptors.

Just a few versions ago we added curl_multi_wait() as a way to avoid the 1024
limit for the "normal" API by using poll() underneath but without exposing
this to the outside. This made it even simpler for "typical" applications to
wait for libcurl's and the application's own transfers.

To me, it sounds like perhaps curl_multi_wait() would be the easiest way to
solve your immediate problem.

> This project is a maintenance project ,so I don't want to change a lot of
> code to cause any side effect. So I think can I just use curl_multi_setopt
> set the callback function before curl_multi_add_handle and when the call
> back happen , I add the fd into pullfd array. Then I poll on the pullfd
> array to replace the select I used to call.But when my code execute it will
> stuck when multi curl happen. Does anyone have any idea why my code not
> working?

Those little snippets weren't enough for me to figure out how everything works
or not. Can you provide a complete example?

List admin:
Received on 2013-03-15