curl_multi_socket.3 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .\" $Id$
  2. .\"
  3. .TH curl_multi_socket 3 "9 Jul 2006" "libcurl 7.16.0" "libcurl Manual"
  4. .SH NAME
  5. curl_multi_socket \- reads/writes available data
  6. .SH SYNOPSIS
  7. .nf
  8. #include <curl/curl.h>
  9. CURLMcode curl_multi_socket_action(CURLM * multi_handle,
  10. curl_socket_t sockfd, int ev_bitmask,
  11. int *running_handles);
  12. .fi
  13. .B "Now deprecated versions:"
  14. .nf
  15. CURLMcode curl_multi_socket(CURLM * multi_handle, curl_socket_t sockfd,
  16. int *running_handles);
  17. CURLMcode curl_multi_socket_all(CURLM *multi_handle,
  18. int *running_handles);
  19. .fi
  20. .SH DESCRIPTION
  21. Alternative versions of \fIcurl_multi_perform(3)\fP that allows the
  22. application to pass in the file descriptor/socket that has been detected to
  23. have \&"action" on it and let libcurl perform. This lets libcurl avoid having
  24. to scan through all possible file descriptors to check for action.
  25. When the application has detected action on a socket handled by libcurl, it
  26. should call \fIcurl_multi_socket_action(3)\fP with the \fBsockfd\fP argument
  27. set to the socket with the action. When the events on a socket are known, they
  28. can be passed as an events bitmask \fBev_bitmask\fP by first setting
  29. \fBev_bitmask\fP to 0, and then adding using bitwise OR (|) any combination of
  30. events to be chosen from CURL_CSELECT_IN, CURL_CSELECT_OUT or
  31. CURL_CSELECT_ERR. When the events on a socket are unknown, pass 0 instead, and
  32. libcurl will test the descriptor internally.
  33. At return, the integer \fBrunning_handles\fP points to will contain the number
  34. of still running easy handles within the multi handle. When this number
  35. reaches zero, all transfers are complete/done. Note that when you call
  36. \fIcurl_multi_socket_action(3)\fP on a specific socket and the counter
  37. decreases by one, it DOES NOT necessarily mean that this exact socket/transfer
  38. is the one that completed. Use \fIcurl_multi_info_read(3)\fP to figure out
  39. which easy handle that completed.
  40. The \fBcurl_multi_socket_action(3)\fP functions inform the application about
  41. updates in the socket (file descriptor) status by doing none, one, or multiple
  42. calls to the socket callback function set with the CURLMOPT_SOCKETFUNCTION
  43. option to \fIcurl_multi_setopt(3)\fP. They update the status with changes
  44. since the previous time the callback was called.
  45. Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION\fP option with
  46. \fIcurl_multi_setopt(3)\fP. Your application will then get called with
  47. information on how long to wait for socket actions at most before doing the
  48. timeout action: call the \fBcurl_multi_socket_action(3)\fP function with the
  49. \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
  50. \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
  51. for an event-based system using the callback is far better than relying on
  52. polling the timeout value.
  53. Usage of \fIcurl_multi_socket(3)\fP is deprecated, whereas the function is
  54. equivalent to \fIcurl_multi_socket_action(3)\fP with \fBev_bitmask\fP set to
  55. 0.
  56. Force libcurl to (re-)check all its internal sockets and transfers instead of
  57. just a single one by calling \fBcurl_multi_socket_all(3)\fP. Note that there
  58. should not be any reason to use this function!
  59. .SH "CALLBACK DETAILS"
  60. The socket \fBcallback\fP function uses a prototype like this
  61. .nf
  62. int curl_socket_callback(CURL *easy, /* easy handle */
  63. curl_socket_t s, /* socket */
  64. int action, /* see values below */
  65. void *userp, /* private callback pointer */
  66. void *socketp); /* private socket pointer */
  67. .fi
  68. The callback MUST return 0.
  69. The \fIeasy\fP argument is a pointer to the easy handle that deals with this
  70. particular socket. Note that a single handle may work with several sockets
  71. simultaneously.
  72. The \fIs\fP argument is the actual socket value as you use it within your
  73. system.
  74. The \fIaction\fP argument to the callback has one of five values:
  75. .RS
  76. .IP "CURL_POLL_NONE (0)"
  77. register, not interested in readiness (yet)
  78. .IP "CURL_POLL_IN (1)"
  79. register, interested in read readiness
  80. .IP "CURL_POLL_OUT (2)"
  81. register, interested in write readiness
  82. .IP "CURL_POLL_INOUT (3)"
  83. register, interested in both read and write readiness
  84. .IP "CURL_POLL_REMOVE (4)"
  85. unregister
  86. .RE
  87. The \fIsocketp\fP argument is a private pointer you have previously set with
  88. \fIcurl_multi_assign(3)\fP to be associated with the \fIs\fP socket. If no
  89. pointer has been set, socketp will be NULL. This argument is of course a
  90. service to applications that want to keep certain data or structs that are
  91. strictly associated to the given socket.
  92. The \fIuserp\fP argument is a private pointer you have previously set with
  93. \fIcurl_multi_setopt(3)\fP and the CURLMOPT_SOCKETDATA option.
  94. .SH "RETURN VALUE"
  95. CURLMcode type, general libcurl multi interface error code.
  96. Legacy: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this basically means
  97. that you should call \fIcurl_multi_socket(3)\fP again, before you wait for
  98. more actions on libcurl's sockets. You don't have to do it immediately, but
  99. the return code means that libcurl may have more data available to return or
  100. that there may be more data to send off before it is "satisfied".
  101. In modern libcurls, \fICURLM_CALL_MULTI_PERFORM\fP or
  102. \fICURLM_CALL_MULTI_SOKCET\fP should not be returned and no application needs
  103. to care about them.
  104. NOTE that the return code is for the whole multi stack. Problems still might have
  105. occurred on individual transfers even when one of these functions
  106. return OK.
  107. .SH "TYPICAL USAGE"
  108. 1. Create a multi handle
  109. 2. Set the socket callback with CURLMOPT_SOCKETFUNCTION
  110. 3. Set the timeout callback with CURLMOPT_TIMERFUNCTION, to get to know what
  111. timeout value to use when waiting for socket activities.
  112. 4. Add easy handles with curl_multi_add_handle()
  113. 5. Provide some means to manage the sockets libcurl is using, so you can check
  114. them for activity. This can be done through your application code, or by way
  115. of an external library such as libevent or glib.
  116. 6. Wait for activity on any of libcurl's sockets, use the timeout value your
  117. callback has been told
  118. 7, When activity is detected, call curl_multi_socket_action() for the
  119. socket(s) that got action. If no activity is detected and the timeout expires,
  120. call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP
  121. 8. Go back to step 6.
  122. .SH AVAILABILITY
  123. This function was added in libcurl 7.15.4, and is deemed stable since
  124. 7.16.0.
  125. \fIcurl_multi_socket(3)\fP is deprecated, use
  126. \fIcurl_multi_socket_action(3)\fP instead!
  127. .SH "SEE ALSO"
  128. .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
  129. .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
  130. .BR "the hiperfifo.c example"