curl_multi_wait.3 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. .\" generated by cd2nroff 0.1 from curl_multi_wait.md
  2. .TH curl_multi_wait 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_wait \- poll on all easy handles in a multi handle
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_wait(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_wait(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 being used
  20. instead to make sure timeout accuracy is reasonably kept.
  21. The calling application may pass additional \fIcurl_waitfd\fP structures which
  22. are similar to \fIpoll(2)\fP\(aqs \fIpollfd\fP structure to be waited on in the
  23. same 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. If no extra file descriptors are provided and libcurl has no file descriptor
  29. to offer to wait for, this function returns immediately. (Consider using
  30. \fIcurl_multi_poll(3)\fP to avoid this behavior.)
  31. This function is encouraged to be used instead of select(3) when using the
  32. multi interface to allow applications to easier circumvent the common problem
  33. with 1024 maximum file descriptors.
  34. .SH curl_waitfd
  35. .nf
  36. struct curl_waitfd {
  37. curl_socket_t fd;
  38. short events;
  39. short revents;
  40. };
  41. .fi
  42. .IP CURL_WAIT_POLLIN
  43. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on read
  44. events such as new data received.
  45. .IP CURL_WAIT_POLLPRI
  46. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on high
  47. priority read events such as out of band data.
  48. .IP CURL_WAIT_POLLOUT
  49. Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on
  50. write events such as the socket being clear to write without blocking.
  51. .SH PROTOCOLS
  52. This functionality affects all supported protocols
  53. .SH EXAMPLE
  54. .nf
  55. int main(void)
  56. {
  57. CURL *easy;
  58. CURLM *multi = curl_multi_init();
  59. int still_running;
  60. /* add the individual easy handle */
  61. curl_multi_add_handle(multi, easy);
  62. do {
  63. CURLMcode mc;
  64. int numfds;
  65. mc = curl_multi_perform(multi, &still_running);
  66. if(mc == CURLM_OK) {
  67. /* wait for activity, timeout or "nothing" */
  68. mc = curl_multi_wait(multi, NULL, 0, 1000, &numfds);
  69. }
  70. if(mc != CURLM_OK) {
  71. fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
  72. break;
  73. }
  74. } while(still_running);
  75. curl_multi_remove_handle(multi, easy);
  76. }
  77. .fi
  78. .SH AVAILABILITY
  79. Added in curl 7.28.0
  80. .SH RETURN VALUE
  81. CURLMcode type, general libcurl multi interface error code. See
  82. \fIlibcurl\-errors(3)\fP
  83. .SH SEE ALSO
  84. .BR curl_multi_fdset (3),
  85. .BR curl_multi_perform (3),
  86. .BR curl_multi_poll (3)