curl_multi_waitfds.3 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .\" generated by cd2nroff 0.1 from curl_multi_waitfds.md
  2. .TH curl_multi_waitfds 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_waitfds \- extract file descriptor information from a multi handle
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. #include <stdlib.h>
  9. CURLMcode curl_multi_waitfds(CURLM *multi,
  10. struct curl_waitfd *ufds,
  11. unsigned int size,
  12. unsigned int *fd_count);
  13. .fi
  14. .SH DESCRIPTION
  15. This function extracts \fIcurl_waitfd\fP structures which are similar to
  16. \fIpoll(2)\fP\(aqs \fIpollfd\fP structure from a given multi_handle.
  17. These structures can be used for polling on multi_handle file descriptors in a
  18. fashion similar to \fIcurl_multi_poll(3)\fP. The \fIcurl_multi_perform(3)\fP
  19. function should be called as soon as one of them is ready to be read from or
  20. written to.
  21. libcurl fills provided \fIufds\fP array up to the \fIsize\fP.
  22. If a number of descriptors used by the multi_handle is greater than the
  23. \fIsize\fP parameter then libcurl returns CURLM_OUT_OF_MEMORY error.
  24. If the \fIfd_count\fP argument is not a null pointer, it points to a variable
  25. that on returns specifies the number of descriptors used by the multi_handle to
  26. be checked for being ready to read or write.
  27. The client code can pass \fIsize\fP equal to zero just to get the number of the
  28. descriptors and allocate appropriate storage for them to be used in a
  29. subsequent function call.
  30. .SH PROTOCOLS
  31. This functionality affects all supported protocols
  32. .SH EXAMPLE
  33. .nf
  34. int main(void)
  35. {
  36. CURLMcode mc;
  37. struct curl_waitfd *ufds;
  38. CURLM *multi = curl_multi_init();
  39. do {
  40. /* call curl_multi_perform() */
  41. /* get the count of file descriptors from the transfers */
  42. unsigned int fd_count = 0;
  43. mc = curl_multi_waitfds(multi, NULL, 0, &fd_count);
  44. if(mc != CURLM_OK) {
  45. fprintf(stderr, "curl_multi_waitfds() failed, code %d.\\n", mc);
  46. break;
  47. }
  48. if(!fd_count)
  49. continue; /* no descriptors yet */
  50. /* Allocate storage for our descriptors.
  51. * Note that a better approach can be used to minimize allocations and
  52. * deallocations, if needed, like pre-allocated or grow-only array.
  53. */
  54. ufds = (struct curl_waitfd*)malloc(fd_count * sizeof(struct curl_waitfd));
  55. /* get wait descriptors from the transfers and put them into array. */
  56. mc = curl_multi_waitfds(multi, ufds, fd_count, NULL);
  57. if(mc != CURLM_OK) {
  58. fprintf(stderr, "curl_multi_waitfds() failed, code %d.\\n", mc);
  59. free(ufds);
  60. break;
  61. }
  62. /* Do polling on descriptors in ufds */
  63. free(ufds);
  64. } while (!mc);
  65. }
  66. .fi
  67. .SH AVAILABILITY
  68. Added in curl 8.8.0
  69. .SH RETURN VALUE
  70. \fBCURLMcode\fP type, general libcurl multi interface error code. See
  71. \fIlibcurl\-errors(3)\fP
  72. .SH SEE ALSO
  73. .BR curl_multi_fdset (3),
  74. .BR curl_multi_perform (3),
  75. .BR curl_multi_poll (3),
  76. .BR curl_multi_wait (3)