2
0

curl_multi_wait.3 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_wait 3 "12 Jul 2012" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_multi_wait - polls on all easy handles in a multi handle
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. CURLMcode curl_multi_wait(CURLM *multi_handle,
  31. struct curl_waitfd extra_fds[],
  32. unsigned int extra_nfds,
  33. int timeout_ms,
  34. int *numfds);
  35. .ad
  36. .SH DESCRIPTION
  37. \fIcurl_multi_wait(3)\fP polls all file descriptors used by the curl easy
  38. handles contained in the given multi handle set. It will block until activity
  39. is detected on at least one of the handles or \fItimeout_ms\fP has passed.
  40. Alternatively, if the multi handle has a pending internal timeout that has a
  41. shorter expiry time than \fItimeout_ms\fP, that shorter time will be used
  42. instead to make sure timeout accuracy is reasonably kept.
  43. The calling application may pass additional \fIcurl_waitfd\fP structures which
  44. are similar to \fIpoll(2)\fP's \fIpollfd\fP structure to be waited on in the
  45. same call.
  46. On completion, if \fInumfds\fP is non-NULL, it will be populated with the
  47. total number of file descriptors on which interesting events occurred. This
  48. number can include both libcurl internal descriptors as well as descriptors
  49. provided in \fIextra_fds\fP.
  50. If no extra file descriptors are provided and libcurl has no file descriptor
  51. to offer to wait for, this function will return immediately. (Try
  52. \fIcurl_multi_poll(3)\fP instead if you rather avoid this behavior.)
  53. This function is encouraged to be used instead of select(3) when using the
  54. multi interface to allow applications to easier circumvent the common problem
  55. with 1024 maximum file descriptors.
  56. .SH curl_waitfd
  57. .nf
  58. struct curl_waitfd {
  59. curl_socket_t fd;
  60. short events;
  61. short revents;
  62. };
  63. .fi
  64. .IP CURL_WAIT_POLLIN
  65. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on read
  66. events such as new data received.
  67. .IP CURL_WAIT_POLLPRI
  68. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on high
  69. priority read events such as out of band data.
  70. .IP CURL_WAIT_POLLOUT
  71. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on
  72. write events such as the socket being clear to write without blocking.
  73. .SH EXAMPLE
  74. .nf
  75. CURL *easy_handle;
  76. CURLM *multi_handle;
  77. /* add the individual easy handle */
  78. curl_multi_add_handle(multi_handle, easy_handle);
  79. do {
  80. CURLMcode mc;
  81. int numfds;
  82. mc = curl_multi_perform(multi_handle, &still_running);
  83. if(mc == CURLM_OK ) {
  84. /* wait for activity, timeout or "nothing" */
  85. mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
  86. }
  87. if(mc != CURLM_OK) {
  88. fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
  89. break;
  90. }
  91. /* 'numfds' being zero means either a timeout or no file descriptors to
  92. wait for. Try timeout on first occurrence, then assume no file
  93. descriptors and no file descriptors to wait for means wait for 100
  94. milliseconds. */
  95. if(!numfds) {
  96. repeats++; /* count number of repeated zero numfds */
  97. if(repeats > 1) {
  98. WAITMS(100); /* sleep 100 milliseconds */
  99. }
  100. }
  101. else
  102. repeats = 0;
  103. } while(still_running);
  104. curl_multi_remove_handle(multi_handle, easy_handle);
  105. .fi
  106. .SH AVAILABILITY
  107. This function was added in libcurl 7.28.0.
  108. .SH RETURN VALUE
  109. CURLMcode type, general libcurl multi interface error code. See
  110. \fIlibcurl-errors(3)\fP
  111. .SH "SEE ALSO"
  112. .BR curl_multi_fdset "(3), " curl_multi_perform "(3), " curl_multi_poll "(3), "