curl_multi_wait.3 4.4 KB

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