1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_BUFFERSIZE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_MAXFILESIZE (3)
9  - CURLOPT_MAX_RECV_SPEED_LARGE (3)
10  - CURLOPT_UPLOAD_BUFFERSIZE (3)
11  - CURLOPT_WRITEFUNCTION (3)
12Protocol:
13  - All
14---
15
16# NAME
17
18CURLOPT_BUFFERSIZE - receive buffer size
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_BUFFERSIZE, long size);
26~~~
27
28# DESCRIPTION
29
30Pass a long specifying your preferred *size* (in bytes) for the receive buffer
31in libcurl. The main point of this would be that the write callback gets
32called more often and with smaller chunks. Secondly, for some protocols, there
33is a benefit of having a larger buffer for performance.
34
35This is just treated as a request, not an order. You cannot be guaranteed to
36actually get the given size.
37
38This buffer size is by default *CURL_MAX_WRITE_SIZE* (16kB). The maximum
39buffer size allowed to be set is *CURL_MAX_READ_SIZE* (10MB). The minimum
40buffer size allowed to be set is 1024.
41
42DO NOT set this option on a handle that is currently used for an active
43transfer as that may lead to unintended consequences.
44
45The maximum size was 512kB until 7.88.0.
46
47Starting in libcurl 8.7.0, there is just a single transfer buffer allocated
48per multi handle. This buffer is used by all easy handles added to a multi
49handle no matter how many parallel transfers there are. The buffer remains
50allocated as long as there are active transfers.
51
52# DEFAULT
53
54CURL_MAX_WRITE_SIZE (16kB)
55
56# EXAMPLE
57
58~~~c
59int main(void)
60{
61  CURL *curl = curl_easy_init();
62  if(curl) {
63    CURLcode res;
64    curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/foo.bin");
65
66    /* ask libcurl to allocate a larger receive buffer */
67    curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 120000L);
68
69    res = curl_easy_perform(curl);
70
71    curl_easy_cleanup(curl);
72  }
73}
74~~~
75
76# AVAILABILITY
77
78Added in 7.10. Growing the buffer was added in 7.53.0.
79
80# RETURN VALUE
81
82Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
83