curl_easy_pause.3 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. .\" generated by cd2nroff 0.1 from curl_easy_pause.md
  2. .TH curl_easy_pause 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_easy_pause \- pause and unpause a connection
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_pause(CURL *handle, int bitmask );
  9. .fi
  10. .SH DESCRIPTION
  11. Using this function, you can explicitly mark a running connection to get
  12. paused, and you can unpause a connection that was previously paused. Unlike
  13. most other libcurl functions, \fIcurl_easy_pause(3)\fP can be used from within
  14. callbacks.
  15. A connection can be paused by using this function or by letting the read or
  16. the write callbacks return the proper magic return code
  17. (\fICURL_READFUNC_PAUSE\fP and \fICURL_WRITEFUNC_PAUSE\fP). A write callback
  18. that returns pause signals to the library that it could not take care of any
  19. data at all, and that data is then delivered again to the callback when the
  20. transfer is unpaused.
  21. While it may feel tempting, take care and notice that you cannot call this
  22. function from another thread. To unpause, you may for example call it from the
  23. progress callback (\fICURLOPT_PROGRESSFUNCTION(3)\fP).
  24. When this function is called to unpause receiving, the write callback might
  25. get called before this function returns to deliver cached content. When
  26. libcurl delivers such cached data to the write callback, it is delivered as
  27. fast as possible, which may overstep the boundary set in
  28. \fICURLOPT_MAX_RECV_SPEED_LARGE(3)\fP etc.
  29. The \fBhandle\fP argument identifies the transfer you want to pause or
  30. unpause.
  31. A paused transfer is excluded from low speed cancels via the
  32. \fICURLOPT_LOW_SPEED_LIMIT(3)\fP option and unpausing a transfer resets the
  33. time period required for the low speed limit to be met.
  34. The \fBbitmask\fP argument is a set of bits that sets the new state of the
  35. connection. The following bits can be used:
  36. .IP CURLPAUSE_RECV
  37. Pause receiving data. There is no data received on this connection until this
  38. function is called again without this bit set. Thus, the write callback
  39. (\fICURLOPT_WRITEFUNCTION(3)\fP) is not called.
  40. .IP CURLPAUSE_SEND
  41. Pause sending data. There is no data sent on this connection until this
  42. function is called again without this bit set. Thus, the read callback
  43. (\fICURLOPT_READFUNCTION(3)\fP) is not called.
  44. .IP CURLPAUSE_ALL
  45. Convenience define that pauses both directions.
  46. .IP CURLPAUSE_CONT
  47. Convenience define that unpauses both directions.
  48. .SH LIMITATIONS
  49. The pausing of transfers does not work with protocols that work without
  50. network connectivity, like FILE://. Trying to pause such a transfer, in any
  51. direction, might cause problems or error.
  52. .SH MULTIPLEXED
  53. When a connection is used multiplexed, like for HTTP/2, and one of the
  54. transfers over the connection is paused and the others continue flowing,
  55. libcurl might end up buffering contents for the paused transfer. It has to do
  56. this because it needs to drain the socket for the other transfers and the
  57. already announced window size for the paused transfer allows the server to
  58. continue sending data up to that window size amount. By default, libcurl
  59. announces a 32 megabyte window size, which thus can make libcurl end up
  60. buffering 32 megabyte of data for a paused stream.
  61. When such a paused stream is unpaused again, any buffered data is delivered
  62. first.
  63. .SH PROTOCOLS
  64. This functionality affects all supported protocols
  65. .SH EXAMPLE
  66. .nf
  67. int main(void)
  68. {
  69. CURL *curl = curl_easy_init();
  70. if(curl) {
  71. /* pause a transfer in both directions */
  72. curl_easy_pause(curl, CURLPAUSE_RECV | CURLPAUSE_SEND);
  73. }
  74. }
  75. .fi
  76. .SH MEMORY USE
  77. When pausing a download transfer by returning the magic return code from a
  78. write callback, the read data is already in libcurl\(aqs internal buffers so it
  79. has to keep it in an allocated buffer until the receiving is again unpaused
  80. using this function.
  81. If the downloaded data is compressed and is asked to get uncompressed
  82. automatically on download, libcurl continues to uncompress the entire
  83. downloaded chunk and it caches the data uncompressed. This has the side\-
  84. effect that if you download something that is compressed a lot, it can result
  85. in a large data amount needing to be allocated to save the data during the
  86. pause. Consider not using paused receiving if you allow libcurl to uncompress
  87. data automatically.
  88. If the download is done with HTTP/2 or HTTP/3, there is up to a stream window
  89. size worth of data that curl cannot stop but instead needs to cache while the
  90. transfer is paused. This means that if a window size of 64 MB is used, libcurl
  91. might end up having to cache 64 MB of data.
  92. .SH AVAILABILITY
  93. Added in curl 7.18.0
  94. .SH RETURN VALUE
  95. CURLE_OK (zero) means that the option was set properly, and a non\-zero return
  96. code means something wrong occurred after the new state was set. See the
  97. \fIlibcurl\-errors(3)\fP man page for the full list with descriptions.
  98. .SH SEE ALSO
  99. .BR curl_easy_cleanup (3),
  100. .BR curl_easy_reset (3)