2
0

curl_multi_socket_action.3 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.haxx.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .TH curl_multi_socket_action 3 "9 Jul 2006" "libcurl 7.16.0" "libcurl Manual"
  23. .SH NAME
  24. curl_multi_socket_action \- reads/writes available data given an action
  25. .SH SYNOPSIS
  26. .nf
  27. #include <curl/curl.h>
  28. CURLMcode curl_multi_socket_action(CURLM * multi_handle,
  29. curl_socket_t sockfd,
  30. int ev_bitmask,
  31. int *running_handles);
  32. .fi
  33. .SH DESCRIPTION
  34. When the application has detected action on a socket handled by libcurl, it
  35. should call \fIcurl_multi_socket_action(3)\fP with the \fBsockfd\fP argument
  36. set to the socket with the action. When the events on a socket are known, they
  37. can be passed as an events bitmask \fBev_bitmask\fP by first setting
  38. \fBev_bitmask\fP to 0, and then adding using bitwise OR (|) any combination of
  39. events to be chosen from CURL_CSELECT_IN, CURL_CSELECT_OUT or
  40. CURL_CSELECT_ERR. When the events on a socket are unknown, pass 0 instead, and
  41. libcurl will test the descriptor internally. It is also permissible to pass
  42. CURL_SOCKET_TIMEOUT to the \fBsockfd\fP parameter in order to initiate the
  43. whole process or when a timeout occurs.
  44. At return, \fBrunning_handles\fP points to the number of running easy handles
  45. within the multi handle. When this number reaches zero, all transfers are
  46. complete/done. When you call \fIcurl_multi_socket_action(3)\fP on a specific
  47. socket and the counter decreases by one, it DOES NOT necessarily mean that
  48. this exact socket/transfer is the one that completed. Use
  49. \fIcurl_multi_info_read(3)\fP to figure out which easy handle that completed.
  50. The \fIcurl_multi_socket_action(3)\fP function informs the application about
  51. updates in the socket (file descriptor) status by doing none, one, or multiple
  52. calls to the socket callback function set with the
  53. \fICURLMOPT_SOCKETFUNCTION(3)\fP option to \fIcurl_multi_setopt(3)\fP. They
  54. update the status with changes since the previous time the callback was
  55. called.
  56. Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION(3)\fP option
  57. with \fIcurl_multi_setopt(3)\fP. Your application will then get called with
  58. information on how long to wait for socket actions at most before doing the
  59. timeout action: call the \fIcurl_multi_socket_action(3)\fP function with the
  60. \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
  61. \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
  62. for an event-based system using the callback is far better than relying on
  63. polling the timeout value.
  64. .SH "TYPICAL USAGE"
  65. 1. Create a multi handle
  66. 2. Set the socket callback with \fICURLMOPT_SOCKETFUNCTION(3)\fP
  67. 3. Set the timeout callback with \fICURLMOPT_TIMERFUNCTION(3)\fP, to get to
  68. know what timeout value to use when waiting for socket activities.
  69. 4. Add easy handles with curl_multi_add_handle()
  70. 5. Provide some means to manage the sockets libcurl is using, so you can check
  71. them for activity. This can be done through your application code, or by way
  72. of an external library such as libevent or glib.
  73. 6. Call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...)
  74. to kickstart everything. To get one or more callbacks called.
  75. 7. Wait for activity on any of libcurl's sockets, use the timeout value your
  76. callback has been told.
  77. 8, When activity is detected, call curl_multi_socket_action() for the
  78. socket(s) that got action. If no activity is detected and the timeout expires,
  79. call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
  80. .SH AVAILABILITY
  81. This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
  82. .SH "SEE ALSO"
  83. .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
  84. .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
  85. .BR "the hiperfifo.c example"