cURL / Mailing Lists / curl-library / Single Mail


how to use poll with libcurl

From: jianqiu lv <>
Date: Thu, 14 Mar 2013 23:24:39 +0800

  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. 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.
  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
  Here is part of my code.(the code look almost the same as

    static void setsock(curl_socket_t s, CURL*e, int act, CurlMultiEngine*g)
      int kind =


      struct pollfd ufd;
      ufd.fd = s; = kind;

    /*call back for curl_multi_setopt CURLMOPT_SOCKETFUNCTION */
    static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void
    CurlMultiEngine *mapleCMERI = (CurlMultiEngine*) cbp;

      if (what != CURL_POLL_REMOVE) {
        setsock(s, e, what, mapleCMERI);
      return 0;

    CurlMultiEngine::setPollFd(pollfd ufd)
    int i = 0;
    for(; i<m_ufdsPosition;i++)
    if(ufds[i].fd == ufd.fd)
     ufds[i] = ufd;
    if(i == m_ufdsPosition)
     ufds[m_ufdsPosition++] = ufd;

    CurlMultiEngine::multiSelect(int a_waitTime)
//replace select with poll to avoid fd 1024 limit
        int result = poll(ufds,m_ufdsPosition,a_waitTime);
        return result;

List admin:
Received on 2013-03-14