2
0

README.multi_socket 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. Implementation of the curl_multi_socket API
  2. The main ideas of the new API are simply:
  3. 1 - The application can use whatever event system it likes as it gets info
  4. from libcurl about what file descriptors libcurl waits for what action
  5. on. (The previous API returns fd_sets which is very select()-centric).
  6. 2 - When the application discovers action on a single socket, it calls
  7. libcurl and informs that there was action on this particular socket and
  8. libcurl can then act on that socket/transfer only and not care about
  9. any other transfers. (The previous API always had to scan through all
  10. the existing transfers.)
  11. The idea is that curl_multi_socket_action() calls a given callback with
  12. information about what socket to wait for what action on, and the callback
  13. only gets called if the status of that socket has changed.
  14. We also added a timer callback that makes libcurl call the application when
  15. the timeout value changes, and you set that with curl_multi_setopt() and the
  16. CURLMOPT_TIMERFUNCTION option. To get this to work, Internally, there's an
  17. added a struct to each easy handle in which we store an "expire time" (if
  18. any). The structs are then "splay sorted" so that we can add and remove
  19. times from the linked list and yet somewhat swiftly figure out both how long
  20. time there is until the next nearest timer expires and which timer (handle)
  21. we should take care of now. Of course, the upside of all this is that we get
  22. a curl_multi_timeout() that should also work with old-style applications
  23. that use curl_multi_perform().
  24. We created an internal "socket to easy handles" hash table that given
  25. a socket (file descriptor) return the easy handle that waits for action on
  26. that socket. This hash is made using the already existing hash code
  27. (previously only used for the DNS cache).
  28. To make libcurl able to report plain sockets in the socket callback, we had
  29. to re-organize the internals of the curl_multi_fdset() etc so that the
  30. conversion from sockets to fd_sets for that function is only done in the
  31. last step before the data is returned. I also had to extend c-ares to get a
  32. function that can return plain sockets, as that library too returned only
  33. fd_sets and that is no longer good enough. The changes done to c-ares are
  34. available in c-ares 1.3.1 and later.
  35. We have done a test runs with up to 9000 connections (with a single active
  36. one). The curl_multi_socket_action() invoke then takes less than 10
  37. microseconds in average (using the read-only-1-byte-at-a-time hack). We are
  38. now below the 60 microseconds "per socket action" goal (the extra 50 is the
  39. time libevent needs).
  40. Documentation
  41. http://curl.haxx.se/libcurl/c/curl_multi_socket_action.html
  42. http://curl.haxx.se/libcurl/c/curl_multi_timeout.html
  43. http://curl.haxx.se/libcurl/c/curl_multi_setopt.html