curl_multi_socket_action.3 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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.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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH curl_multi_socket_action 3 "9 Jul 2006" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_multi_socket_action \- reads/writes available data given an action
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. CURLMcode curl_multi_socket_action(CURLM *multi_handle,
  31. curl_socket_t sockfd,
  32. int ev_bitmask,
  33. int *running_handles);
  34. .fi
  35. .SH DESCRIPTION
  36. When the application has detected action on a socket handled by libcurl, it
  37. should call \fIcurl_multi_socket_action(3)\fP with the \fBsockfd\fP argument
  38. set to the socket with the action. When the events on a socket are known, they
  39. can be passed as an events bitmask \fBev_bitmask\fP by first setting
  40. \fBev_bitmask\fP to 0, and then adding using bitwise OR (|) any combination of
  41. events to be chosen from CURL_CSELECT_IN, CURL_CSELECT_OUT or
  42. CURL_CSELECT_ERR. When the events on a socket are unknown, pass 0 instead, and
  43. libcurl will test the descriptor internally. It is also permissible to pass
  44. CURL_SOCKET_TIMEOUT to the \fBsockfd\fP parameter in order to initiate the
  45. whole process or when a timeout occurs.
  46. At return, \fBrunning_handles\fP points to the number of running easy handles
  47. within the multi handle. When this number reaches zero, all transfers are
  48. complete/done. When you call \fIcurl_multi_socket_action(3)\fP on a specific
  49. socket and the counter decreases by one, it DOES NOT necessarily mean that
  50. this exact socket/transfer is the one that completed. Use
  51. \fIcurl_multi_info_read(3)\fP to figure out which easy handle that completed.
  52. The \fIcurl_multi_socket_action(3)\fP function informs the application about
  53. updates in the socket (file descriptor) status by doing none, one, or multiple
  54. calls to the socket callback function set with the
  55. \fICURLMOPT_SOCKETFUNCTION(3)\fP option to \fIcurl_multi_setopt(3)\fP. They
  56. update the status with changes since the previous time the callback was
  57. called.
  58. Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION(3)\fP option
  59. with \fIcurl_multi_setopt(3)\fP. Your application will then get called with
  60. information on how long to wait for socket actions at most before doing the
  61. timeout action: call the \fIcurl_multi_socket_action(3)\fP function with the
  62. \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
  63. \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
  64. for an event-based system using the callback is far better than relying on
  65. polling the timeout value.
  66. When this function returns error, the state of all transfers are uncertain and
  67. they cannot be continued. \fIcurl_multi_socket_action(3)\fP should not be
  68. called again on the same multi handle after an error has been returned, unless
  69. first removing all the handles and adding new ones.
  70. .SH "TYPICAL USAGE"
  71. 1. Create a multi handle
  72. 2. Set the socket callback with \fICURLMOPT_SOCKETFUNCTION(3)\fP
  73. 3. Set the timeout callback with \fICURLMOPT_TIMERFUNCTION(3)\fP, to get to
  74. know what timeout value to use when waiting for socket activities.
  75. 4. Add easy handles with curl_multi_add_handle()
  76. 5. Provide some means to manage the sockets libcurl is using, so you can check
  77. them for activity. This can be done through your application code, or by way
  78. of an external library such as libevent or glib.
  79. 6. Call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...)
  80. to kickstart everything. To get one or more callbacks called.
  81. 7. Wait for activity on any of libcurl's sockets, use the timeout value your
  82. callback has been told.
  83. 8, When activity is detected, call curl_multi_socket_action() for the
  84. socket(s) that got action. If no activity is detected and the timeout expires,
  85. call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
  86. .SH EXAMPLE
  87. .nf
  88. /* the event-library gets told when there activity on the socket 'fd',
  89. which we translate to a call to curl_multi_socket_action() */
  90. int running;
  91. rc = curl_multi_socket_action(multi_handle, fd, EVENT,
  92. &running);
  93. .fi
  94. .SH AVAILABILITY
  95. This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
  96. .SH RETURN VALUE
  97. CURLMcode type, general libcurl multi interface error code. See
  98. \fIlibcurl-errors(3)\fP
  99. .SH "SEE ALSO"
  100. .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
  101. .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
  102. .BR "the hiperfifo.c example"