79139adf1b3c0863f1a0d437ce2d9bcc152a1c5a
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_READFUNCTION.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2014, 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 http://curl.haxx.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 .\" **************************************************************************
22 .\"
23 .TH CURLOPT_READFUNCTION 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
24 .SH NAME
25 CURLOPT_READFUNCTION \- read callback for data uploads
26 .SH SYNOPSIS
27 #include <curl/curl.h>
28
29 size_t read_callback(char *buffer, size_t size, size_t nitems, void *instream);
30
31 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_READFUNCTION, read_callback);
32
33 .SH DESCRIPTION
34 Pass a pointer to your callback function, as the prototype shows above.
35
36 This callback function gets called by libcurl as soon as it needs to read data
37 in order to send it to the peer. The data area pointed at by the pointer
38 \fIbuffer\fP should be filled up with at most \fIsize\fP multiplied with
39 \fInmemb\fP number of bytes by your function.
40
41 Your function must then return the actual number of bytes that it stored in
42 that memory area. Returning 0 will signal end-of-file to the library and cause
43 it to stop the current transfer.
44
45 If you stop the current transfer by returning 0 "pre-maturely" (i.e before the
46 server expected it, like when you've said you will upload N bytes and you
47 upload less than N bytes), you may experience that the server "hangs" waiting
48 for the rest of the data that won't come.
49
50 The read callback may return \fICURL_READFUNC_ABORT\fP to stop the current
51 operation immediately, resulting in a \fICURLE_ABORTED_BY_CALLBACK\fP error
52 code from the transfer.
53
54 The callback can return \fICURL_READFUNC_PAUSE\fP to cause reading from this
55 connection to pause. See \fIcurl_easy_pause(3)\fP for further details.
56
57 \fBBugs\fP: when doing TFTP uploads, you must return the exact amount of data
58 that the callback wants, or it will be considered the final packet by the
59 server end and the transfer will end there.
60
61 If you set this callback pointer to NULL, or don't set it at all, the default
62 internal read function will be used. It is doing an fread() on the FILE *
63 userdata set with \fICURLOPT_READDATA(3)\fP.
64 .SH DEFAULT
65 The default internal read callback is fread().
66 .SH PROTOCOLS
67 This is used for all protocols when doing uploads.
68 .SH EXAMPLE
69 Here's an example setting a read callback for reading that to upload to an FTP
70 site: http://curl.haxx.se/libcurl/c/ftpupload.html
71 .SH AVAILABILITY
72 CURL_READFUNC_PAUSE return code was added in 7.18.0 and CURL_READFUNC_ABORT
73 was added in 7.12.1.
74 .SH RETURN VALUE
75 This will return CURLE_OK.
76 .SH "SEE ALSO"
77 .BR CURLOPT_READDATA "(3), " CURLOPT_WRITEFUNCTION "(3), "
78 .BR CURLOPT_SEEKFUNCTION "(3), "