curl_easy_pause.3 5.7 KB

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