1CURLOPT_READFUNCTION(3)    curl_easy_setopt options    CURLOPT_READFUNCTION(3)
2
3
4

NAME

6       CURLOPT_READFUNCTION - read callback for data uploads
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       size_t  read_callback(char  *buffer,  size_t  size, size_t nitems, void
12       *userdata);
13
14       CURLcode    curl_easy_setopt(CURL    *handle,     CURLOPT_READFUNCTION,
15       read_callback);
16
17

DESCRIPTION

19       Pass a pointer to your callback function, as the prototype shows above.
20
21       This  callback  function  gets called by libcurl as soon as it needs to
22       read data in order to send it to the peer -  like  if  you  ask  it  to
23       upload  or  post  data  to  the server. The data area pointed at by the
24       pointer buffer should be filled up with at most  size  multiplied  with
25       nitems number of bytes by your function.
26
27       Set the userdata argument with the CURLOPT_READDATA(3) option.
28
29       Your  function must return the actual number of bytes that it stored in
30       the data area pointed at by the pointer buffer. Returning 0 will signal
31       end-of-file to the library and cause it to stop the current transfer.
32
33       If  you  stop  the  current transfer by returning 0 "pre-maturely" (i.e
34       before the server expected it, like when you've said you will upload  N
35       bytes  and  you  upload less than N bytes), you may experience that the
36       server "hangs" waiting for the rest of the data that won't come.
37
38       The read callback may return CURL_READFUNC_ABORT to  stop  the  current
39       operation  immediately,  resulting in a CURLE_ABORTED_BY_CALLBACK error
40       code from the transfer.
41
42       The callback can return CURL_READFUNC_PAUSE to cause reading from  this
43       connection to pause. See curl_easy_pause(3) for further details.
44
45       Bugs: when doing TFTP uploads, you must return the exact amount of data
46       that the callback wants, or it will be considered the final  packet  by
47       the server end and the transfer will end there.
48
49       If  you  set this callback pointer to NULL, or don't set it at all, the
50       default internal read function will be used. It is doing an fread()  on
51       the FILE * userdata set with CURLOPT_READDATA(3).
52

DEFAULT

54       The default internal read callback is fread().
55

PROTOCOLS

57       This is used for all protocols when doing uploads.
58

EXAMPLE

60       Here's an example setting a read callback for reading that to upload to
61       an FTP site: https://curl.haxx.se/libcurl/c/ftpupload.html
62

AVAILABILITY

64       CURL_READFUNC_PAUSE return code was  added  in  7.18.0  and  CURL_READ‐
65       FUNC_ABORT was added in 7.12.1.
66

RETURN VALUE

68       This will return CURLE_OK.
69

SEE ALSO

71       CURLOPT_READDATA(3), CURLOPT_WRITEFUNCTION(3), CURLOPT_SEEKFUNCTION(3),
72       CURLOPT_UPLOAD(3), CURLOPT_POST(3),
73
74
75
76libcurl 7.64.0                  August 11, 2018        CURLOPT_READFUNCTION(3)
Impressum