cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Specific questions on curl_multi_perform and curl_socket_action

From: Yehezkel Horowitz <horowity_at_checkpoint.com>
Date: Thu, 15 Dec 2011 16:11:22 +0200

>Hello,
 
>I recently started moving from synchronous curl easy handle approach to the asynchronous way using curl multi handle.
> But I am stuck with some questions before finally making a choice between curl multi perform and curl socket action.
 
>My questions  are as below:
 
>1)      Nature of my application: My application always would want to have a fixed number of connections all the time (may be 10 to 15 connections). Nature of the server is that of a  file uploader or downloader.
What would be best to select? Curl_multi_perform or curl_socket_action approach?
curl_multi_socket_action is the new interface for curl_multi - use it.
 
>2)      I can see form the man page of curl_socket_action, it says application or external library (libevent or glib) has to check for activity on sockets. How is this different from select based approach used by  curl_multi_perform, as libevent internally uses select.
You can choose to use select, but also can choose to use epoll, which is faster and allow you to have more than 1024 connections at the time, but this is YOUR choise.

>3)      When curl calls the callback set with CURLMOPT_SOCKETFUNCTION, what is the necessity of setting another callback with libevent library? How different are these two call backs?

Think that curl_multi send a request to the server, now it want to return the control to your application, but to handle 2 cases - first the request was answered within a given timeout, second - the request was not answered within this timeout.
So it will do it with 2 callbacks:
1. CURLMOPT_SOCKETFUNCTION - to indicate multi_curl that an event actually happened.
2. CURLMOPT_TIMERFUNCTION - to indicate multi_curl that the timeout passed.

>4)      And my basic doubt is, what is the socket data structure's significance here. I understand we create a job(may be a url to upload or download) and assign the job to curl handle, and the curl handle takes care of all http communication. So what is the role of socket data structure here. I could not completely understand its significance from the examples.

Since curl handle events that happens on sockets (COM events), it should handle socket data structure. In most cases you just want to pass the needed action to your underline socket control (select/epoll).
 
>Please share your valuable comments.
 
>Thanks,
>-Sandeep

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