curl_multi_perform.3 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .\" generated by cd2nroff 0.1 from curl_multi_perform.md
  2. .TH curl_multi_perform 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_perform \- run all transfers until it would block
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles);
  9. .fi
  10. .SH DESCRIPTION
  11. This function performs transfers on all the added handles that need attention
  12. in a non\-blocking fashion. The easy handles have previously been added to the
  13. multi handle with \fIcurl_multi_add_handle(3)\fP.
  14. When an application has found out there is data available for the multi_handle
  15. or a timeout has elapsed, the application should call this function to
  16. read/write whatever there is to read or write right now etc.
  17. \fIcurl_multi_perform(3)\fP returns as soon as the reads/writes are done. This
  18. function does not require that there actually is any data available for
  19. reading or that data can be written, it can be called just in case. It stores
  20. the number of handles that still transfer data in the second argument\(aqs
  21. integer\-pointer.
  22. If the amount of \fIrunning_handles\fP is changed from the previous call (or
  23. is less than the amount of easy handles you have added to the multi handle),
  24. you know that there is one or more transfers less "running". You can then call
  25. \fIcurl_multi_info_read(3)\fP to get information about each individual
  26. completed transfer, and that returned info includes CURLcode and more. If an
  27. added handle fails quickly, it may never be counted as a running_handle. You
  28. could use \fIcurl_multi_info_read(3)\fP to track actual status of the added
  29. handles in that case.
  30. When \fIrunning_handles\fP is set to zero (0) on the return of this function,
  31. there is no longer any transfers in progress.
  32. When this function returns error, the state of all transfers are uncertain and
  33. they cannot be continued. \fIcurl_multi_perform(3)\fP should not be called
  34. again on the same multi handle after an error has been returned, unless first
  35. removing all the handles and adding new ones.
  36. .SH PROTOCOLS
  37. This functionality affects all supported protocols
  38. .SH EXAMPLE
  39. .nf
  40. int main(void)
  41. {
  42. int still_running;
  43. CURL *multi = curl_multi_init();
  44. CURL *curl = curl_easy_init();
  45. if(curl) {
  46. curl_multi_add_handle(multi, curl);
  47. do {
  48. CURLMcode mc = curl_multi_perform(multi, &still_running);
  49. if(!mc && still_running)
  50. /* wait for activity, timeout or "nothing" */
  51. mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
  52. if(mc) {
  53. fprintf(stderr, "curl_multi_poll() failed, code %d.\\n", (int)mc);
  54. break;
  55. }
  56. /* if there are still transfers, loop! */
  57. } while(still_running);
  58. }
  59. }
  60. .fi
  61. .SH AVAILABILITY
  62. Added in curl 7.9.6
  63. .SH RETURN VALUE
  64. CURLMcode type, general libcurl multi interface error code.
  65. This function returns errors regarding the whole multi stack. Problems on
  66. individual transfers may have occurred even when this function returns
  67. \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure out how individual
  68. transfers did.
  69. .SH TYPICAL USAGE
  70. Most applications use \fIcurl_multi_poll(3)\fP to make libcurl wait for
  71. activity on any of the ongoing transfers. As soon as one or more file
  72. descriptor has activity or the function times out, the application calls
  73. \fIcurl_multi_perform(3)\fP.
  74. .SH SEE ALSO
  75. .BR curl_multi_add_handle (3),
  76. .BR curl_multi_cleanup (3),
  77. .BR curl_multi_fdset (3),
  78. .BR curl_multi_info_read (3),
  79. .BR curl_multi_init (3),
  80. .BR curl_multi_wait (3),
  81. .BR libcurl-errors (3)