curl_multi_fdset.3 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .\" generated by cd2nroff 0.1 from curl_multi_fdset.md
  2. .TH curl_multi_fdset 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_fdset \- extract file descriptor information from a multi handle
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_fdset(CURLM *multi_handle,
  9. fd_set *read_fd_set,
  10. fd_set *write_fd_set,
  11. fd_set *exc_fd_set,
  12. int *max_fd);
  13. .fi
  14. .SH DESCRIPTION
  15. This function extracts file descriptor information from a given multi_handle.
  16. libcurl returns its \fIfd_set\fP sets. The application can use these to
  17. select() on, but be sure to \fIFD_ZERO\fP them before calling this function as
  18. \fIcurl_multi_fdset(3)\fP only adds its own descriptors, it does not zero or
  19. otherwise remove any others. The \fIcurl_multi_perform(3)\fP function should
  20. be called as soon as one of them is ready to be read from or written to.
  21. The \fIread_fd_set\fP argument should point to an object of type \fBfd_set\fP
  22. that on returns specifies the file descriptors to be checked for being ready
  23. to read.
  24. The \fIwrite_fd_set\fP argument should point to an object of type \fBfd_set\fP
  25. that on return specifies the file descriptors to be checked for being ready to
  26. write.
  27. The \fIexc_fd_set\fP argument should point to an object of type \fBfd_set\fP
  28. that on return specifies the file descriptors to be checked for error
  29. conditions.
  30. If no file descriptors are set by libcurl, \fImax_fd\fP contain \-1 when this
  31. function returns. Otherwise it contains the highest descriptor number libcurl
  32. set. When libcurl returns \-1 in \fImax_fd\fP, it is because libcurl currently
  33. does something that is not possible for your application to monitor with a
  34. socket and unfortunately you can then not know exactly when the current action
  35. is completed using select(). You then need to wait a while before you proceed
  36. and call \fIcurl_multi_perform(3)\fP anyway. How long to wait? Unless
  37. \fIcurl_multi_timeout(3)\fP gives you a lower number, we suggest 100
  38. milliseconds or so, but you may want to test it out in your own particular
  39. conditions to find a suitable value.
  40. When doing select(), you should use \fIcurl_multi_timeout(3)\fP to figure out
  41. how long to wait for action. Call \fIcurl_multi_perform(3)\fP even if no
  42. activity has been seen on the \fBfd_sets\fP after the timeout expires as
  43. otherwise internal retries and timeouts may not work as you would think and
  44. want.
  45. If one of the sockets used by libcurl happens to be larger than what can be
  46. set in an \fBfd_set\fP, which on POSIX systems means that the file descriptor
  47. is larger than \fBFD_SETSIZE\fP, then libcurl tries to not set it. Setting a
  48. too large file descriptor in an \fBfd_set\fP implies an out of bounds write
  49. which can cause crashes, or worse. The effect of NOT storing it might possibly
  50. save you from the crash, but makes your program NOT wait for sockets it should
  51. wait for...
  52. .SH PROTOCOLS
  53. This functionality affects all supported protocols
  54. .SH EXAMPLE
  55. .nf
  56. int main(void)
  57. {
  58. fd_set fdread;
  59. fd_set fdwrite;
  60. fd_set fdexcep;
  61. int maxfd;
  62. int rc;
  63. CURLMcode mc;
  64. struct timeval timeout = {1, 0};
  65. CURLM *multi = curl_multi_init();
  66. do {
  67. /* call curl_multi_perform() */
  68. /* get file descriptors from the transfers */
  69. mc = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
  70. if(mc != CURLM_OK) {
  71. fprintf(stderr, "curl_multi_fdset() failed, code %d.\\n", mc);
  72. break;
  73. }
  74. /* wait for activity on one of the sockets */
  75. rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  76. } while(!mc);
  77. }
  78. .fi
  79. .SH AVAILABILITY
  80. Added in curl 7.9.6
  81. .SH RETURN VALUE
  82. \fBCURLMcode\fP type, general libcurl multi interface error code. See
  83. \fIlibcurl\-errors(3)\fP
  84. .SH SEE ALSO
  85. .BR curl_multi_cleanup (3),
  86. .BR curl_multi_init (3),
  87. .BR curl_multi_perform (3),
  88. .BR curl_multi_timeout (3),
  89. .BR curl_multi_wait (3),
  90. .BR curl_multi_waitfds (3),
  91. .BR select (2)