Revert "Imported Upstream version 7.44.0"
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_READFUNCTION.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2  "http://www.w3.org/TR/html4/loose.dtd">
3 <html><head>
4 <title>CURLOPT_READFUNCTION man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
7 P.level0 {
8  padding-left: 2em;
9 }
10
11 P.level1 {
12  padding-left: 4em;
13 }
14
15 P.level2 {
16  padding-left: 6em;
17 }
18
19 span.emphasis {
20  font-style: italic;
21 }
22
23 span.bold {
24  font-weight: bold;
25 }
26
27 span.manpage {
28  font-weight: bold;
29 }
30
31 h2.nroffsh {
32  background-color: #e0e0e0;
33 }
34
35 span.nroffip {
36  font-weight: bold;
37  font-size: 120%;
38  font-family: monospace;
39 }
40
41 p.roffit {
42  text-align: center;
43  font-size: 80%;
44 }
45 </STYLE>
46 </head><body>
47
48 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
49 <p class="level0">CURLOPT_READFUNCTION - read callback for data uploads <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
50 <p class="level0">#include &lt;curl/curl.h&gt; 
51 <p class="level0">size_t read_callback(char *buffer, size_t size, size_t nitems, void *instream); 
52 <p class="level0">CURLcode curl_easy_setopt(CURL *handle, CURLOPT_READFUNCTION, read_callback); 
53 <p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
54 <p class="level0">Pass a pointer to your callback function, as the prototype shows above. 
55 <p class="level0">This callback function gets called by libcurl as soon as it needs to read data in order to send it to the peer. The data area pointed at by the pointer <span Class="emphasis">buffer</span> should be filled up with at most <span Class="emphasis">size</span> multiplied with <span Class="emphasis">nmemb</span> number of bytes by your function. 
56 <p class="level0">Your function must then return the actual number of bytes that it stored in that memory area. Returning 0 will signal end-of-file to the library and cause it to stop the current transfer. 
57 <p class="level0">If you stop the current transfer by returning 0 "pre-maturely" (i.e before the server expected it, like when you've said you will upload N bytes and you upload less than N bytes), you may experience that the server "hangs" waiting for the rest of the data that won't come. 
58 <p class="level0">The read callback may return <span Class="emphasis">CURL_READFUNC_ABORT</span> to stop the current operation immediately, resulting in a <span Class="emphasis">CURLE_ABORTED_BY_CALLBACK</span> error code from the transfer. 
59 <p class="level0">The callback can return <span Class="emphasis">CURL_READFUNC_PAUSE</span> to cause reading from this connection to pause. See <span Class="emphasis">curl_easy_pause(3)</span> for further details. 
60 <p class="level0"><span Class="bold">Bugs</span>: when doing TFTP uploads, you must return the exact amount of data that the callback wants, or it will be considered the final packet by the server end and the transfer will end there. 
61 <p class="level0">If you set this callback pointer to NULL, or don't set it at all, the default internal read function will be used. It is doing an fread() on the FILE * userdata set with <a Class="emphasis" href="./CURLOPT_READDATA.html">CURLOPT_READDATA</a>. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
62 <p class="level0">The default internal read callback is fread(). <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
63 <p class="level0">This is used for all protocols when doing uploads. <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
64 <p class="level0">Here's an example setting a read callback for reading that to upload to an FTP site: <a href="http://curl.haxx.se/libcurl/c/ftpupload.html">http://curl.haxx.se/libcurl/c/ftpupload.html</a> <a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
65 <p class="level0">CURL_READFUNC_PAUSE return code was added in 7.18.0 and CURL_READFUNC_ABORT was added in 7.12.1. <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
66 <p class="level0">This will return CURLE_OK. <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
67 <p class="level0"><a Class="manpage" href="./CURLOPT_READDATA.html">CURLOPT_READDATA</a>, <a Class="manpage" href="./CURLOPT_WRITEFUNCTION.html">CURLOPT_WRITEFUNCTION</a>, <span Class="manpage"> </span> <a Class="manpage" href="./CURLOPT_SEEKFUNCTION.html">CURLOPT_SEEKFUNCTION</a>, <span Class="manpage"> </span> <p class="roffit">
68  This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
69 </body></html>