curl_multi_perform.3 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.haxx.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .TH curl_multi_perform 3 "1 March 2002" "libcurl 7.9.5" "libcurl Manual"
  23. .SH NAME
  24. curl_multi_perform - reads/writes available data from each easy handle
  25. .SH SYNOPSIS
  26. #include <curl/curl.h>
  27. CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles);
  28. .ad
  29. .SH DESCRIPTION
  30. This function handles transfers on all the added handles that need attention
  31. in an non-blocking fashion.
  32. When an application has found out there's data available for the multi_handle
  33. or a timeout has elapsed, the application should call this function to
  34. read/write whatever there is to read or write right now etc.
  35. \fIcurl_multi_perform(3)\fP returns as soon as the reads/writes are done. This
  36. function does not require that there actually is any data available for
  37. reading or that data can be written, it can be called just in case. It will
  38. write the number of handles that still transfer data in the second argument's
  39. integer-pointer.
  40. If the amount of \fIrunning_handles\fP is changed from the previous call (or
  41. is less than the amount of easy handles you've added to the multi handle), you
  42. know that there is one or more transfers less "running". You can then call
  43. \fIcurl_multi_info_read(3)\fP to get information about each individual
  44. completed transfer, and that returned info includes CURLcode and more. If an
  45. added handle fails very quickly, it may never be counted as a running_handle.
  46. You could use \fIcurl_multi_info_read(3)\fP to track actual status of the
  47. added handles in that case.
  48. When \fIrunning_handles\fP is set to zero (0) on the return of this function,
  49. there is no longer any transfers in progress.
  50. .SH EXAMPLE
  51. .nf
  52. #ifdef _WIN32
  53. #define SHORT_SLEEP Sleep(100)
  54. #else
  55. #define SHORT_SLEEP usleep(100000)
  56. #endif
  57. fd_set fdread;
  58. fd_set fdwrite;
  59. fd_set fdexcep;
  60. int maxfd = -1;
  61. long curl_timeo;
  62. curl_multi_timeout(multi_handle, &curl_timeo);
  63. if(curl_timeo < 0)
  64. curl_timeo = 1000;
  65. timeout.tv_sec = curl_timeo / 1000;
  66. timeout.tv_usec = (curl_timeo % 1000) * 1000;
  67. FD_ZERO(&fdread);
  68. FD_ZERO(&fdwrite);
  69. FD_ZERO(&fdexcep);
  70. /* get file descriptors from the transfers */
  71. mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
  72. if(maxfd == -1) {
  73. SHORT_SLEEP;
  74. rc = 0;
  75. }
  76. else
  77. rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
  78. switch(rc) {
  79. case -1:
  80. /* select error */
  81. break;
  82. case 0:
  83. default:
  84. /* timeout or readable/writable sockets */
  85. curl_multi_perform(multi_handle, &still_running);
  86. break;
  87. }
  88. /* if there are still transfers, loop! */
  89. .fi
  90. .SH "RETURN VALUE"
  91. CURLMcode type, general libcurl multi interface error code.
  92. Before version 7.20.0 (released on February 9 2010): If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
  93. basically means that you should call \fIcurl_multi_perform(3)\fP again, before
  94. you select() on more actions. You don't have to do it immediately, but the
  95. return code means that libcurl may have more data available to return or that
  96. there may be more data to send off before it is "satisfied". Do note that
  97. \fIcurl_multi_perform(3)\fP will return \fICURLM_CALL_MULTI_PERFORM\fP only
  98. when it wants to be called again \fBimmediately\fP. When things are fine and
  99. there is nothing immediate it wants done, it'll return \fICURLM_OK\fP and you
  100. need to wait for \&"action" and then call this function again.
  101. This function only returns errors etc regarding the whole multi stack.
  102. Problems still might have occurred on individual transfers even when this
  103. function returns \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure
  104. out how individual transfers did.
  105. .SH "TYPICAL USAGE"
  106. Most applications will use \fIcurl_multi_fdset(3)\fP to get the multi_handle's
  107. file descriptors, and \fIcurl_multi_timeout(3)\fP to get a suitable timeout
  108. period, then it'll wait for action on the file descriptors using
  109. \fBselect(3)\fP. As soon as one or more file descriptor is ready,
  110. \fIcurl_multi_perform(3)\fP gets called.
  111. .SH "SEE ALSO"
  112. .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
  113. .BR curl_multi_wait "(3), "
  114. .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
  115. .BR libcurl-errors "(3)"