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: Wed, 28 Sep 2011 13:43:38 +0200 (CEST)

On Wed, 28 Sep 2011, venkataragavan vijayakumar wrote:

> Our requirement is using single thread/process calling the libcurl API's to
> do HTTP POST and getting response from the server by asynchronous way. Since
> curl_easy_perform is a blocking call, we went to multi_perform

That makes sense.

> 1. creating easy handle , using easy_setopt setting the POST requirements.
> 2. Then adding the *easy handle* to *multi handle* . and execute the *multi
> perform* until it finishes the operation.
> 3. But we are struggling to get the clue how to get the response from the
> server through libcurl.

With CURLOPT_WRITEFUNCTION. The libcurl will call your callback with all data
it receives.

> Whether we need to pass the socket fd to libcurl, If so , how to do that?
> Any particular API is for that. Please give us that.

You don't need that and you don't want that.

> FD_SET is given by the multi_fdset API , we will do the select(),after that
> we will call the curl_multi_socket_action(), but it needs the socket fd.

You really don't seem to need the socket at all. If you *would* want to know
the sockets libcurl uses, then I'd recommend using the multi_socket API.

The multi_socket API is designed to allow you to use your own event library,
so you then add easy handles to the multi handle, you set the
CURLMOPT_SOCKETFUNCTION callback with curl_multi_setopt() and then you call
curl_multi_socket_action().

Then libcurl will inform you what sockets it uses. When you find activity on
any of the sockets libcurl uses, you inform libcurl about that with
curl_multi_socket_action().

-- 
  / 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-28