curl-library
Re: curl_multi_socket_action: second argument?
Date: Sat, 23 Jun 2012 18:53:45 +0200
On Thu, Jun 21, 2012 at 4:46 PM, Felix E. Klee <felix.klee_at_inka.de>
wrote:
> Helpful would be an example list of steps for a typical retrieval
> [...]
What follows is the coarse flow of a program that watches a database and
downloads data from requested URLs.
Key events for exactly one request (query), which is successful:
1. Program start
The event loop is started.
2. Timer event (database-watcher)
Timer event (database-watcher)
...
The database is checked every half a second until finally a request
(URL) is available.
Once a request is available, the event handler constructs a query
based on the URL. The associated cURL easy handle is passed to
curl_multi_add_handle().
curl_multi_add_handle() calls CURLMOPT_TIMERFUNCTION with a timeout of
just 1 ms. CURLMOPT_TIMERFUNCTION adjust the timeout for the
check-cURL-handles-watcher.
3. Timer event (check-cURL-handles-watcher)
The event handler checks the cURL easy handles by calling
curl_multi_socket_action() with CURL_SOCKET_TIMEOUT. Remember that in
this example there is just one cURL easy handle.
curl_multi_socket_action():
a) Calls CURLMOPT_SOCKETFUNCTION, which sets up a socket-watcher for
the socket associated with the cURL easy handle. The socket-watcher
is instructed to watch IO-read-events (EV_READ).
b) Calls CURLMOPT_TIMERFUNCTION with timeout 39999 ms (= 40 s = far in
the future).
4. IO-read-event (socket-watcher)
The event handler calls curl_multi_socket_action() for the socket.
curl_multi_socket_action() calls CURLMOPT_SOCKETFUNCTION, which
updates the socket-watcher to watch IO-write-events (EV_WRITE).
5. IO-write-event (socket-watcher)
IO-write-event (socket-watcher)
...
Data is available, repeatedly. Every time:
a) The event handler calls curl_multi_socket_action() for the socket.
b) curl_multi_socket_action() calls CURLOPT_WRITEFUNCTION, which
appends retrieved data into the database.
6. IO-write-event (socket-watcher)
The transfer is done.
a) The event handler calls curl_multi_socket_action() for the socket.
b) curl_multi_socket_action() calls CURLMOPT_SOCKETFUNCTION, which
removes the socket-watcher.
c) curl_multi_socket_action() calls CURLMOPT_TIMERFUNCTION with a
timeout of -1 ms (= reach timeout immediately).
d) CURLMOPT_TIMERFUNCTION calls curl_multi_socket_action() with
CURL_SOCKET_TIMEOUT.
e) CURLMOPT_TIMERFUNCTION finishes up the completed query (frees up
resources, etc.).
f) CURLMOPT_TIMERFUNCTION halts the check-cURL-handles-watcher.
How I named the cURL multi callback functions to make clear what is
going on:
* CURLMOPT_SOCKETFUNCTION: on_update_socket_watcher
* CURLMOPT_TIMERFUNCTION: on_timeout_changed
What is not clear to me yet: What writes into the socket?
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-06-23