curl_multi_poll.3 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_poll 3 "29 Jul 2019" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_multi_poll - polls on all easy handles in a multi handle
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. CURLMcode curl_multi_poll(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_poll(3)\fP polls all file descriptors used by the curl easy
  38. handles contained in the given multi handle set. It blocks until activity is
  39. 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 is used instead
  42. to make sure timeout accuracy is reasonably kept.
  43. The calling application may pass additional curl_waitfd structures which are
  44. similar to \fIpoll(2)\fP's \fIpollfd\fP structure to be waited on in the same
  45. call.
  46. On completion, if \fInumfds\fP is non-NULL, it gets populated with the total
  47. number of file descriptors on which interesting events occurred. This number
  48. can include both libcurl internal descriptors as well as descriptors provided
  49. in \fIextra_fds\fP.
  50. The \fIcurl_multi_wakeup(3)\fP function can be used from another thread to
  51. wake up this function and return faster. This is one of the details
  52. that makes this function different than \fIcurl_multi_wait(3)\fP which cannot
  53. be woken up this way.
  54. If no extra file descriptors are provided and libcurl has no file descriptor
  55. to offer to wait for, this function instead waits during \fItimeout_ms\fP
  56. milliseconds (or shorter if an internal timer indicates so). This is the other
  57. detail that makes this function different than \fIcurl_multi_wait(3)\fP.
  58. This function is encouraged to be used instead of select(3) when using the
  59. multi interface to allow applications to easier circumvent the common problem
  60. with 1024 maximum file descriptors.
  61. .SH curl_waitfd
  62. .nf
  63. struct curl_waitfd {
  64. curl_socket_t fd;
  65. short events;
  66. short revents;
  67. };
  68. .fi
  69. .IP CURL_WAIT_POLLIN
  70. Bit flag to curl_waitfd.events indicating the socket should poll on read
  71. events such as new data received.
  72. .IP CURL_WAIT_POLLPRI
  73. Bit flag to curl_waitfd.events indicating the socket should poll on high
  74. priority read events such as out of band data.
  75. .IP CURL_WAIT_POLLOUT
  76. Bit flag to curl_waitfd.events indicating the socket should poll on write
  77. events such as the socket being clear to write without blocking.
  78. .SH EXAMPLE
  79. .nf
  80. CURL *easy_handle;
  81. CURLM *multi_handle;
  82. /* add the individual easy handle */
  83. curl_multi_add_handle(multi_handle, easy_handle);
  84. do {
  85. CURLMcode mc;
  86. int numfds;
  87. mc = curl_multi_perform(multi_handle, &still_running);
  88. if(mc == CURLM_OK) {
  89. /* wait for activity or timeout */
  90. mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
  91. }
  92. if(mc != CURLM_OK) {
  93. fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
  94. break;
  95. }
  96. } while(still_running);
  97. curl_multi_remove_handle(multi_handle, easy_handle);
  98. .fi
  99. .SH AVAILABILITY
  100. Added in 7.66.0.
  101. .SH RETURN VALUE
  102. CURLMcode type, general libcurl multi interface error code. See
  103. \fIlibcurl-errors(3)\fP
  104. .SH "SEE ALSO"
  105. .BR curl_multi_fdset "(3), " curl_multi_perform "(3), "
  106. .BR curl_multi_wait "(3), " curl_multi_wakeup "(3)"