quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl_easy_pause.md (4917B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: curl_easy_pause
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - curl_easy_cleanup (3)
      9   - curl_easy_reset (3)
     10 Protocol:
     11   - All
     12 Added-in: 7.18.0
     13 ---
     14 
     15 # NAME
     16 
     17 curl_easy_pause - pause and unpause a connection
     18 
     19 # SYNOPSIS
     20 
     21 ~~~c
     22 #include <curl/curl.h>
     23 
     24 CURLcode curl_easy_pause(CURL *handle, int bitmask );
     25 ~~~
     26 
     27 # DESCRIPTION
     28 
     29 Using this function, you can explicitly mark a running connection to get
     30 paused, and you can unpause a connection that was previously paused. Unlike
     31 most other libcurl functions, curl_easy_pause(3) can be used from within
     32 callbacks.
     33 
     34 A connection can be paused by using this function or by letting the read or
     35 the write callbacks return the proper magic return code
     36 (*CURL_READFUNC_PAUSE* and *CURL_WRITEFUNC_PAUSE*). A write callback
     37 that returns pause signals to the library that it could not take care of any
     38 data at all, and that data is then delivered again to the callback when the
     39 transfer is unpaused.
     40 
     41 While it may feel tempting, take care and notice that you cannot call this
     42 function from another thread. To unpause, you may for example call it from the
     43 progress callback (CURLOPT_PROGRESSFUNCTION(3)).
     44 
     45 When this function is called to unpause receiving, the write callback might
     46 get called before this function returns to deliver cached content. When
     47 libcurl delivers such cached data to the write callback, it is delivered as
     48 fast as possible, which may overstep the boundary set in
     49 CURLOPT_MAX_RECV_SPEED_LARGE(3) etc.
     50 
     51 The **handle** argument identifies the transfer you want to pause or
     52 unpause.
     53 
     54 A paused transfer is excluded from low speed cancels via the
     55 CURLOPT_LOW_SPEED_LIMIT(3) option and unpausing a transfer resets the
     56 time period required for the low speed limit to be met.
     57 
     58 The **bitmask** argument is a set of bits that sets the new state of the
     59 connection. The following bits can be used:
     60 
     61 ## CURLPAUSE_RECV
     62 
     63 Pause receiving data. There is no data received on this connection until this
     64 function is called again without this bit set. Thus, the write callback
     65 (CURLOPT_WRITEFUNCTION(3)) is not called.
     66 
     67 ## CURLPAUSE_SEND
     68 
     69 Pause sending data. There is no data sent on this connection until this
     70 function is called again without this bit set. Thus, the read callback
     71 (CURLOPT_READFUNCTION(3)) is not called.
     72 
     73 ## CURLPAUSE_ALL
     74 
     75 Convenience define that pauses both directions.
     76 
     77 ## CURLPAUSE_CONT
     78 
     79 Convenience define that unpauses both directions.
     80 
     81 # LIMITATIONS
     82 
     83 The pausing of transfers does not work with protocols that work without
     84 network connectivity, like FILE://. Trying to pause such a transfer, in any
     85 direction, might cause problems or error.
     86 
     87 # MULTIPLEXED
     88 
     89 When a connection is used multiplexed, like for HTTP/2, and one of the
     90 transfers over the connection is paused and the others continue flowing,
     91 libcurl might end up buffering contents for the paused transfer. It has to do
     92 this because it needs to drain the socket for the other transfers and the
     93 already announced window size for the paused transfer allows the server to
     94 continue sending data up to that window size amount. By default, libcurl
     95 announces a 32 megabyte window size, which thus can make libcurl end up
     96 buffering 32 megabyte of data for a paused stream.
     97 
     98 When such a paused stream is unpaused again, any buffered data is delivered
     99 first.
    100 
    101 # %PROTOCOLS%
    102 
    103 # EXAMPLE
    104 
    105 ~~~c
    106 int main(void)
    107 {
    108   CURL *curl = curl_easy_init();
    109   if(curl) {
    110     /* pause a transfer in both directions */
    111     curl_easy_pause(curl, CURLPAUSE_RECV | CURLPAUSE_SEND);
    112 
    113   }
    114 }
    115 ~~~
    116 
    117 # MEMORY USE
    118 
    119 When pausing a download transfer by returning the magic return code from a
    120 write callback, the read data is already in libcurl's internal buffers so it
    121 has to keep it in an allocated buffer until the receiving is again unpaused
    122 using this function.
    123 
    124 If the downloaded data is compressed and is asked to get uncompressed
    125 automatically on download, libcurl continues to uncompress the entire
    126 downloaded chunk and it caches the data uncompressed. This has the side-
    127 effect that if you download something that is compressed a lot, it can result
    128 in a large data amount needing to be allocated to save the data during the
    129 pause. Consider not using paused receiving if you allow libcurl to uncompress
    130 data automatically.
    131 
    132 If the download is done with HTTP/2 or HTTP/3, there is up to a stream window
    133 size worth of data that curl cannot stop but instead needs to cache while the
    134 transfer is paused. This means that if a window size of 64 MB is used, libcurl
    135 might end up having to cache 64 MB of data.
    136 
    137 # %AVAILABILITY%
    138 
    139 # RETURN VALUE
    140 
    141 This function returns a CURLcode indicating success or error.
    142 
    143 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
    144 libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3)
    145 there can be an error message stored in the error buffer when non-zero is
    146 returned.