xref: /aosp_15_r20/external/curl/docs/libcurl/curl_easy_pause.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_easy_pause
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - curl_easy_cleanup (3)
9*6236dae4SAndroid Build Coastguard Worker  - curl_easy_reset (3)
10*6236dae4SAndroid Build Coastguard WorkerProtocol:
11*6236dae4SAndroid Build Coastguard Worker  - All
12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.18.0
13*6236dae4SAndroid Build Coastguard Worker---
14*6236dae4SAndroid Build Coastguard Worker
15*6236dae4SAndroid Build Coastguard Worker# NAME
16*6236dae4SAndroid Build Coastguard Worker
17*6236dae4SAndroid Build Coastguard Workercurl_easy_pause - pause and unpause a connection
18*6236dae4SAndroid Build Coastguard Worker
19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
20*6236dae4SAndroid Build Coastguard Worker
21*6236dae4SAndroid Build Coastguard Worker~~~c
22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
23*6236dae4SAndroid Build Coastguard Worker
24*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_pause(CURL *handle, int bitmask );
25*6236dae4SAndroid Build Coastguard Worker~~~
26*6236dae4SAndroid Build Coastguard Worker
27*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
28*6236dae4SAndroid Build Coastguard Worker
29*6236dae4SAndroid Build Coastguard WorkerUsing this function, you can explicitly mark a running connection to get
30*6236dae4SAndroid Build Coastguard Workerpaused, and you can unpause a connection that was previously paused. Unlike
31*6236dae4SAndroid Build Coastguard Workermost other libcurl functions, curl_easy_pause(3) can be used from within
32*6236dae4SAndroid Build Coastguard Workercallbacks.
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard WorkerA connection can be paused by using this function or by letting the read or
35*6236dae4SAndroid Build Coastguard Workerthe write callbacks return the proper magic return code
36*6236dae4SAndroid Build Coastguard Worker(*CURL_READFUNC_PAUSE* and *CURL_WRITEFUNC_PAUSE*). A write callback
37*6236dae4SAndroid Build Coastguard Workerthat returns pause signals to the library that it could not take care of any
38*6236dae4SAndroid Build Coastguard Workerdata at all, and that data is then delivered again to the callback when the
39*6236dae4SAndroid Build Coastguard Workertransfer is unpaused.
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard WorkerWhile it may feel tempting, take care and notice that you cannot call this
42*6236dae4SAndroid Build Coastguard Workerfunction from another thread. To unpause, you may for example call it from the
43*6236dae4SAndroid Build Coastguard Workerprogress callback (CURLOPT_PROGRESSFUNCTION(3)).
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard WorkerWhen this function is called to unpause receiving, the write callback might
46*6236dae4SAndroid Build Coastguard Workerget called before this function returns to deliver cached content. When
47*6236dae4SAndroid Build Coastguard Workerlibcurl delivers such cached data to the write callback, it is delivered as
48*6236dae4SAndroid Build Coastguard Workerfast as possible, which may overstep the boundary set in
49*6236dae4SAndroid Build Coastguard WorkerCURLOPT_MAX_RECV_SPEED_LARGE(3) etc.
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard WorkerThe **handle** argument identifies the transfer you want to pause or
52*6236dae4SAndroid Build Coastguard Workerunpause.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard WorkerA paused transfer is excluded from low speed cancels via the
55*6236dae4SAndroid Build Coastguard WorkerCURLOPT_LOW_SPEED_LIMIT(3) option and unpausing a transfer resets the
56*6236dae4SAndroid Build Coastguard Workertime period required for the low speed limit to be met.
57*6236dae4SAndroid Build Coastguard Worker
58*6236dae4SAndroid Build Coastguard WorkerThe **bitmask** argument is a set of bits that sets the new state of the
59*6236dae4SAndroid Build Coastguard Workerconnection. The following bits can be used:
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker## CURLPAUSE_RECV
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard WorkerPause receiving data. There is no data received on this connection until this
64*6236dae4SAndroid Build Coastguard Workerfunction is called again without this bit set. Thus, the write callback
65*6236dae4SAndroid Build Coastguard Worker(CURLOPT_WRITEFUNCTION(3)) is not called.
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Worker## CURLPAUSE_SEND
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard WorkerPause sending data. There is no data sent on this connection until this
70*6236dae4SAndroid Build Coastguard Workerfunction is called again without this bit set. Thus, the read callback
71*6236dae4SAndroid Build Coastguard Worker(CURLOPT_READFUNCTION(3)) is not called.
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker## CURLPAUSE_ALL
74*6236dae4SAndroid Build Coastguard Worker
75*6236dae4SAndroid Build Coastguard WorkerConvenience define that pauses both directions.
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker## CURLPAUSE_CONT
78*6236dae4SAndroid Build Coastguard Worker
79*6236dae4SAndroid Build Coastguard WorkerConvenience define that unpauses both directions.
80*6236dae4SAndroid Build Coastguard Worker
81*6236dae4SAndroid Build Coastguard Worker# LIMITATIONS
82*6236dae4SAndroid Build Coastguard Worker
83*6236dae4SAndroid Build Coastguard WorkerThe pausing of transfers does not work with protocols that work without
84*6236dae4SAndroid Build Coastguard Workernetwork connectivity, like FILE://. Trying to pause such a transfer, in any
85*6236dae4SAndroid Build Coastguard Workerdirection, might cause problems or error.
86*6236dae4SAndroid Build Coastguard Worker
87*6236dae4SAndroid Build Coastguard Worker# MULTIPLEXED
88*6236dae4SAndroid Build Coastguard Worker
89*6236dae4SAndroid Build Coastguard WorkerWhen a connection is used multiplexed, like for HTTP/2, and one of the
90*6236dae4SAndroid Build Coastguard Workertransfers over the connection is paused and the others continue flowing,
91*6236dae4SAndroid Build Coastguard Workerlibcurl might end up buffering contents for the paused transfer. It has to do
92*6236dae4SAndroid Build Coastguard Workerthis because it needs to drain the socket for the other transfers and the
93*6236dae4SAndroid Build Coastguard Workeralready announced window size for the paused transfer allows the server to
94*6236dae4SAndroid Build Coastguard Workercontinue sending data up to that window size amount. By default, libcurl
95*6236dae4SAndroid Build Coastguard Workerannounces a 32 megabyte window size, which thus can make libcurl end up
96*6236dae4SAndroid Build Coastguard Workerbuffering 32 megabyte of data for a paused stream.
97*6236dae4SAndroid Build Coastguard Worker
98*6236dae4SAndroid Build Coastguard WorkerWhen such a paused stream is unpaused again, any buffered data is delivered
99*6236dae4SAndroid Build Coastguard Workerfirst.
100*6236dae4SAndroid Build Coastguard Worker
101*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
102*6236dae4SAndroid Build Coastguard Worker
103*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
104*6236dae4SAndroid Build Coastguard Worker
105*6236dae4SAndroid Build Coastguard Worker~~~c
106*6236dae4SAndroid Build Coastguard Workerint main(void)
107*6236dae4SAndroid Build Coastguard Worker{
108*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
109*6236dae4SAndroid Build Coastguard Worker  if(curl) {
110*6236dae4SAndroid Build Coastguard Worker    /* pause a transfer in both directions */
111*6236dae4SAndroid Build Coastguard Worker    curl_easy_pause(curl, CURLPAUSE_RECV | CURLPAUSE_SEND);
112*6236dae4SAndroid Build Coastguard Worker
113*6236dae4SAndroid Build Coastguard Worker  }
114*6236dae4SAndroid Build Coastguard Worker}
115*6236dae4SAndroid Build Coastguard Worker~~~
116*6236dae4SAndroid Build Coastguard Worker
117*6236dae4SAndroid Build Coastguard Worker# MEMORY USE
118*6236dae4SAndroid Build Coastguard Worker
119*6236dae4SAndroid Build Coastguard WorkerWhen pausing a download transfer by returning the magic return code from a
120*6236dae4SAndroid Build Coastguard Workerwrite callback, the read data is already in libcurl's internal buffers so it
121*6236dae4SAndroid Build Coastguard Workerhas to keep it in an allocated buffer until the receiving is again unpaused
122*6236dae4SAndroid Build Coastguard Workerusing this function.
123*6236dae4SAndroid Build Coastguard Worker
124*6236dae4SAndroid Build Coastguard WorkerIf the downloaded data is compressed and is asked to get uncompressed
125*6236dae4SAndroid Build Coastguard Workerautomatically on download, libcurl continues to uncompress the entire
126*6236dae4SAndroid Build Coastguard Workerdownloaded chunk and it caches the data uncompressed. This has the side-
127*6236dae4SAndroid Build Coastguard Workereffect that if you download something that is compressed a lot, it can result
128*6236dae4SAndroid Build Coastguard Workerin a large data amount needing to be allocated to save the data during the
129*6236dae4SAndroid Build Coastguard Workerpause. Consider not using paused receiving if you allow libcurl to uncompress
130*6236dae4SAndroid Build Coastguard Workerdata automatically.
131*6236dae4SAndroid Build Coastguard Worker
132*6236dae4SAndroid Build Coastguard WorkerIf the download is done with HTTP/2 or HTTP/3, there is up to a stream window
133*6236dae4SAndroid Build Coastguard Workersize worth of data that curl cannot stop but instead needs to cache while the
134*6236dae4SAndroid Build Coastguard Workertransfer is paused. This means that if a window size of 64 MB is used, libcurl
135*6236dae4SAndroid Build Coastguard Workermight end up having to cache 64 MB of data.
136*6236dae4SAndroid Build Coastguard Worker
137*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
138*6236dae4SAndroid Build Coastguard Worker
139*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
140*6236dae4SAndroid Build Coastguard Worker
141*6236dae4SAndroid Build Coastguard WorkerCURLE_OK (zero) means that the option was set properly, and a non-zero return
142*6236dae4SAndroid Build Coastguard Workercode means something wrong occurred after the new state was set. See the
143*6236dae4SAndroid Build Coastguard Workerlibcurl-errors(3) man page for the full list with descriptions.
144