curl_multi_poll.3 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .\" generated by cd2nroff 0.1 from curl_multi_poll.md
  2. .TH curl_multi_poll 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_poll \- poll on all easy handles in a multi handle
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_poll(CURLM *multi_handle,
  9. struct curl_waitfd extra_fds[],
  10. unsigned int extra_nfds,
  11. int timeout_ms,
  12. int *numfds);
  13. .fi
  14. .SH DESCRIPTION
  15. \fIcurl_multi_poll(3)\fP polls all file descriptors used by the curl easy
  16. handles contained in the given multi handle set. It blocks until activity is
  17. detected on at least one of the handles or \fItimeout_ms\fP has passed.
  18. Alternatively, if the multi handle has a pending internal timeout that has a
  19. shorter expiry time than \fItimeout_ms\fP, that shorter time is used instead
  20. to make sure timeout accuracy is reasonably kept.
  21. The calling application may pass additional curl_waitfd structures which are
  22. similar to \fIpoll(2)\fP\(aqs \fIpollfd\fP structure to be waited on in the same
  23. call.
  24. On completion, if \fInumfds\fP is non\-NULL, it gets populated with the total
  25. number of file descriptors on which interesting events occurred. This number
  26. can include both libcurl internal descriptors as well as descriptors provided
  27. in \fIextra_fds\fP.
  28. The \fIcurl_multi_wakeup(3)\fP function can be used from another thread to
  29. wake up this function and return faster. This is one of the details
  30. that makes this function different than \fIcurl_multi_wait(3)\fP which cannot
  31. be woken up this way.
  32. If no extra file descriptors are provided and libcurl has no file descriptor
  33. to offer to wait for, this function instead waits during \fItimeout_ms\fP
  34. milliseconds (or shorter if an internal timer indicates so). This is the other
  35. detail that makes this function different than \fIcurl_multi_wait(3)\fP.
  36. This function is encouraged to be used instead of select(3) when using the
  37. multi interface to allow applications to easier circumvent the common problem
  38. with 1024 maximum file descriptors.
  39. .SH curl_waitfd
  40. .nf
  41. struct curl_waitfd {
  42. curl_socket_t fd;
  43. short events;
  44. short revents;
  45. };
  46. .fi
  47. .IP CURL_WAIT_POLLIN
  48. Bit flag to curl_waitfd.events indicating the socket should poll on read
  49. events such as new data received.
  50. .IP CURL_WAIT_POLLPRI
  51. Bit flag to curl_waitfd.events indicating the socket should poll on high
  52. priority read events such as out of band data.
  53. .IP CURL_WAIT_POLLOUT
  54. Bit flag to curl_waitfd.events indicating the socket should poll on write
  55. events such as the socket being clear to write without blocking.
  56. .SH PROTOCOLS
  57. This functionality affects all supported protocols
  58. .SH EXAMPLE
  59. .nf
  60. int main(void)
  61. {
  62. CURL *easy_handle;
  63. CURLM *multi_handle;
  64. int still_running = 0;
  65. int myfd; /* this is our own file descriptor */
  66. /* add the individual easy handle */
  67. curl_multi_add_handle(multi_handle, easy_handle);
  68. do {
  69. CURLMcode mc;
  70. int numfds;
  71. mc = curl_multi_perform(multi_handle, &still_running);
  72. if(mc == CURLM_OK) {
  73. struct curl_waitfd myown;
  74. myown.fd = myfd;
  75. myown.events = CURL_WAIT_POLLIN; /* wait for input */
  76. myown.revents = 0; /* clear it */
  77. /* wait for activity on curl's descriptors or on our own,
  78. or timeout */
  79. mc = curl_multi_poll(multi_handle, &myown, 1, 1000, &numfds);
  80. if(myown.revents) {
  81. /* did our descriptor receive an event? */
  82. handle_fd(myfd);
  83. }
  84. }
  85. if(mc != CURLM_OK) {
  86. fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
  87. break;
  88. }
  89. } while(still_running);
  90. curl_multi_remove_handle(multi_handle, easy_handle);
  91. }
  92. .fi
  93. .SH AVAILABILITY
  94. Added in curl 7.66.0
  95. .SH RETURN VALUE
  96. CURLMcode type, general libcurl multi interface error code. See
  97. \fIlibcurl\-errors(3)\fP
  98. .SH SEE ALSO
  99. .BR curl_multi_fdset (3),
  100. .BR curl_multi_perform (3),
  101. .BR curl_multi_wait (3),
  102. .BR curl_multi_wakeup (3)