cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: venkataragavan vijayakumar <venkataragavan.v_at_gmail.com>
Date: Thu, 29 Sep 2011 12:39:46 +0530

Hi,

I got the things by using curl_multi_socket_action() and setting the
SOCKET_FUNCTION callback().

In curl_multi_socket_action() it needs socket fd as argument, for that i
have created socket using socket system call and i have passed to it. but in
the socket function callback it gives different socket fd. Is this the right
approach?

steps I have followed.

1. created easy handle
2. created multi handle
3. easy setopt the necessary things
4. add the handle to multi handle.
5. add the socket function to the multi handle.
6. create one socket fd.
7. call the multi_socket_action() with that socket fd.
8. socket callback is called with new socket fd.
9. Again calling the multi_socket_action with new fd.
10. so the operations are getting over and i am getting the HTTP response
perfectly.

please let me know, why socket created by us is not used?

Thanks,
venkat.

On Wed, Sep 28, 2011 at 5:13 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> 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<http://cool.haxx.se/list/listinfo/curl-library>
> Etiquette: http://curl.haxx.se/mail/**etiquette.html<http://curl.haxx.se/mail/etiquette.html>
>

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