cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: how to get socket fd from libcurl in curl multi interface.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 27 Sep 2011 16:40:41 +0200 (CEST)

On Tue, 27 Sep 2011, venkataragavan vijayakumar wrote:

> we are using curl multi interface. we want to read the data from the fd.

I would really really urge you to reconsider that wish. In 101 cases out of a
100 that's the wrong idea and is due to a misunderstanding of how libcurl
works.

> we have got the fdset from the
> CURLMcode curl_multi_fdset(CURLM *multi_handle, fd_set *read_fd_set,
> fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd);
>
> After this we have used select() call.
>
> But we need socket fd, so that we will do FD_ISSET() and then read the data
> from the FD.

You can't even know what the sockets libcurl uses are for, reading from it is
making assumptions of functionality that libcurl will not guarantee and is
likely to break when circumstances chance.

> I have seen curl_multi_socket_action() API, it also needs the socket fd.

Not really. You need to tell libcurl what sockets to act on, yes, but libcurl
has already before that told you which sockets it works on and what it expects
you to wait for on each of those sockets.

See the hiperfifo example for how the multi_socket API works:

         http://curl.haxx.se/libcurl/c/hiperfifo.html

I realize I should add a section to the libcurl-multi.3 man page that explains
the basic idea of the multi_socket API...

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-09-27