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