curl_multi_timeout.3 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. .\" generated by cd2nroff 0.1 from curl_multi_timeout.md
  2. .TH curl_multi_timeout 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_timeout \- how long to wait for action before proceeding
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_timeout(CURLM *multi_handle, long *timeout);
  9. .fi
  10. .SH DESCRIPTION
  11. An application using the libcurl multi interface should call
  12. \fIcurl_multi_timeout(3)\fP to figure out how long it should wait for socket
  13. actions \- at most \- before proceeding.
  14. Proceeding means either doing the socket\-style timeout action: call the
  15. \fIcurl_multi_socket_action(3)\fP function with the \fBsockfd\fP argument set
  16. to CURL_SOCKET_TIMEOUT, or call \fIcurl_multi_perform(3)\fP if you are using
  17. the simpler and older multi interface approach.
  18. The timeout value returned in the long \fBtimeout\fP points to, is in number
  19. of milliseconds at this moment. If 0, it means you should proceed immediately
  20. without waiting for anything. If it returns \-1, there is no timeout at all set.
  21. An application that uses the \fImulti_socket\fP API should not use this function.
  22. It should instead use the \fICURLMOPT_TIMERFUNCTION(3)\fP option for proper and
  23. desired behavior.
  24. Note: if libcurl returns a \-1 timeout here, it just means that libcurl
  25. currently has no stored timeout value. You must not wait too long (more than a
  26. few seconds perhaps) before you call \fIcurl_multi_perform(3)\fP again.
  27. .SH PROTOCOLS
  28. This functionality affects all supported protocols
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. struct timeval timeout;
  34. long timeo;
  35. fd_set fdread;
  36. fd_set fdwrite;
  37. fd_set fdexcep;
  38. int maxfd;
  39. CURLM *multi = curl_multi_init();
  40. curl_multi_timeout(multi, &timeo);
  41. if(timeo < 0)
  42. /* no set timeout, use a default */
  43. timeo = 980;
  44. timeout.tv_sec = timeo / 1000;
  45. timeout.tv_usec = (timeo % 1000) * 1000;
  46. /* wait for activities no longer than the set timeout */
  47. select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  48. }
  49. .fi
  50. .SH TYPICAL USAGE
  51. Call \fIcurl_multi_timeout(3)\fP, then wait for action on the sockets. Figure
  52. out which sockets to wait for by calling \fIcurl_multi_fdset(3)\fP.
  53. When there is activity or timeout, call \fIcurl_multi_perform(3)\fP and then
  54. loop \- until all transfers are complete.
  55. .SH AVAILABILITY
  56. Added in curl 7.15.4
  57. .SH RETURN VALUE
  58. The standard CURLMcode for multi interface error codes.
  59. .SH SEE ALSO
  60. .BR curl_multi_fdset (3),
  61. .BR curl_multi_info_read (3),
  62. .BR curl_multi_setopt (3),
  63. .BR curl_multi_socket (3)