mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
buffer: use data->set.buffer_size instead of BUFSIZE
... to properly use the dynamically set buffer size!
This commit is contained in:
parent
c79f4908d4
commit
e40e9d7f0d
@ -558,12 +558,11 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
|
|||||||
size_t bytestoread;
|
size_t bytestoread;
|
||||||
|
|
||||||
if(size_known) {
|
if(size_known) {
|
||||||
bytestoread =
|
bytestoread = (expected_size < data->set.buffer_size) ?
|
||||||
(expected_size < CURL_OFF_T_C(BUFSIZE) - CURL_OFF_T_C(1)) ?
|
curlx_sotouz(expected_size) : (size_t)data->set.buffer_size;
|
||||||
curlx_sotouz(expected_size) : BUFSIZE - 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bytestoread = BUFSIZE-1;
|
bytestoread = data->set.buffer_size-1;
|
||||||
|
|
||||||
nread = read(fd, buf, bytestoread);
|
nread = read(fd, buf, bytestoread);
|
||||||
|
|
||||||
|
@ -1681,8 +1681,9 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
|
|||||||
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
||||||
do {
|
do {
|
||||||
size_t readthisamountnow =
|
size_t readthisamountnow =
|
||||||
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
|
(data->state.resume_from - passed > data->set.buffer_size) ?
|
||||||
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
|
(size_t)data->set.buffer_size :
|
||||||
|
curlx_sotouz(data->state.resume_from - passed);
|
||||||
|
|
||||||
size_t actuallyread =
|
size_t actuallyread =
|
||||||
data->state.fread_func(data->state.buffer, 1, readthisamountnow,
|
data->state.fread_func(data->state.buffer, 1, readthisamountnow,
|
||||||
|
@ -1117,7 +1117,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
|
|||||||
buffer is using this size.
|
buffer is using this size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sendsize = (size > CURL_MAX_WRITE_SIZE) ? CURL_MAX_WRITE_SIZE : size;
|
sendsize = CURLMIN(size, CURL_MAX_WRITE_SIZE);
|
||||||
|
|
||||||
/* OpenSSL is very picky and we must send the SAME buffer pointer to the
|
/* OpenSSL is very picky and we must send the SAME buffer pointer to the
|
||||||
library when we attempt to re-send this buffer. Sending the same data
|
library when we attempt to re-send this buffer. Sending the same data
|
||||||
@ -2172,8 +2172,9 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
/* when seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
/* when seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
||||||
do {
|
do {
|
||||||
size_t readthisamountnow =
|
size_t readthisamountnow =
|
||||||
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
|
(data->state.resume_from - passed > data->set.buffer_size) ?
|
||||||
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
|
(size_t)data->set.buffer_size :
|
||||||
|
curlx_sotouz(data->state.resume_from - passed);
|
||||||
|
|
||||||
size_t actuallyread =
|
size_t actuallyread =
|
||||||
data->state.fread_func(data->state.buffer, 1, readthisamountnow,
|
data->state.fread_func(data->state.buffer, 1, readthisamountnow,
|
||||||
|
11
lib/sendf.c
11
lib/sendf.c
@ -149,7 +149,7 @@ static void pre_receive_plain(struct connectdata *conn, int num)
|
|||||||
/* Have some incoming data */
|
/* Have some incoming data */
|
||||||
if(!psnd->buffer) {
|
if(!psnd->buffer) {
|
||||||
/* Use buffer double default size for intermediate buffer */
|
/* Use buffer double default size for intermediate buffer */
|
||||||
psnd->allocated_size = 2 * BUFSIZE;
|
psnd->allocated_size = 2 * conn->data->set.buffer_size;
|
||||||
psnd->buffer = malloc(psnd->allocated_size);
|
psnd->buffer = malloc(psnd->allocated_size);
|
||||||
psnd->recv_size = 0;
|
psnd->recv_size = 0;
|
||||||
psnd->recv_processed = 0;
|
psnd->recv_processed = 0;
|
||||||
@ -693,9 +693,10 @@ CURLcode Curl_read(struct connectdata *conn, /* connection data */
|
|||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
size_t bytesfromsocket = 0;
|
size_t bytesfromsocket = 0;
|
||||||
char *buffertofill = NULL;
|
char *buffertofill = NULL;
|
||||||
|
struct Curl_easy *data = conn->data;
|
||||||
|
|
||||||
/* if HTTP/1 pipelining is both wanted and possible */
|
/* if HTTP/1 pipelining is both wanted and possible */
|
||||||
bool pipelining = Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1) &&
|
bool pipelining = Curl_pipeline_wanted(data->multi, CURLPIPE_HTTP1) &&
|
||||||
(conn->bundle->multiuse == BUNDLE_PIPELINING);
|
(conn->bundle->multiuse == BUNDLE_PIPELINING);
|
||||||
|
|
||||||
/* Set 'num' to 0 or 1, depending on which socket that has been sent here.
|
/* Set 'num' to 0 or 1, depending on which socket that has been sent here.
|
||||||
@ -721,13 +722,11 @@ CURLcode Curl_read(struct connectdata *conn, /* connection data */
|
|||||||
}
|
}
|
||||||
/* If we come here, it means that there is no data to read from the buffer,
|
/* If we come here, it means that there is no data to read from the buffer,
|
||||||
* so we read from the socket */
|
* so we read from the socket */
|
||||||
bytesfromsocket = CURLMIN(sizerequested, BUFSIZE * sizeof(char));
|
bytesfromsocket = CURLMIN(sizerequested, (size_t)data->set.buffer_size);
|
||||||
buffertofill = conn->master_buffer;
|
buffertofill = conn->master_buffer;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bytesfromsocket = CURLMIN((long)sizerequested,
|
bytesfromsocket = CURLMIN(sizerequested, (size_t)data->set.buffer_size);
|
||||||
conn->data->set.buffer_size ?
|
|
||||||
conn->data->set.buffer_size : BUFSIZE);
|
|
||||||
buffertofill = buf;
|
buffertofill = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1591,7 +1591,7 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, const ssize_t nread)
|
|||||||
if(!scratch || data->set.crlf) {
|
if(!scratch || data->set.crlf) {
|
||||||
oldscratch = scratch;
|
oldscratch = scratch;
|
||||||
|
|
||||||
scratch = newscratch = malloc(2 * BUFSIZE);
|
scratch = newscratch = malloc(2 * data->set.buffer_size);
|
||||||
if(!newscratch) {
|
if(!newscratch) {
|
||||||
failf(data, "Failed to alloc scratch buffer!");
|
failf(data, "Failed to alloc scratch buffer!");
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -1837,8 +1837,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|||||||
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
|
||||||
do {
|
do {
|
||||||
size_t readthisamountnow =
|
size_t readthisamountnow =
|
||||||
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
|
(data->state.resume_from - passed > data->set.buffer_size) ?
|
||||||
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
|
data->set.buffer_size :
|
||||||
|
curlx_sotouz(data->state.resume_from - passed);
|
||||||
|
|
||||||
size_t actuallyread =
|
size_t actuallyread =
|
||||||
data->state.fread_func(data->state.buffer, 1,
|
data->state.fread_func(data->state.buffer, 1,
|
||||||
|
10
lib/telnet.c
10
lib/telnet.c
@ -1425,7 +1425,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
|
|||||||
if(data->set.is_fread_set) {
|
if(data->set.is_fread_set) {
|
||||||
size_t n;
|
size_t n;
|
||||||
/* read from user-supplied method */
|
/* read from user-supplied method */
|
||||||
n = data->state.fread_func(buf, 1, BUFSIZE - 1, data->state.in);
|
n = data->state.fread_func(buf, 1, buf_size, data->state.in);
|
||||||
if(n == CURL_READFUNC_ABORT) {
|
if(n == CURL_READFUNC_ABORT) {
|
||||||
keepon = FALSE;
|
keepon = FALSE;
|
||||||
result = CURLE_READ_ERROR;
|
result = CURLE_READ_ERROR;
|
||||||
@ -1500,7 +1500,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
|
|||||||
}
|
}
|
||||||
if(events.lNetworkEvents & FD_READ) {
|
if(events.lNetworkEvents & FD_READ) {
|
||||||
/* read data from network */
|
/* read data from network */
|
||||||
result = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
|
result = Curl_read(conn, sockfd, buf, data->set.buffer_size, &nread);
|
||||||
/* read would've blocked. Loop again */
|
/* read would've blocked. Loop again */
|
||||||
if(result == CURLE_AGAIN)
|
if(result == CURLE_AGAIN)
|
||||||
break;
|
break;
|
||||||
@ -1589,7 +1589,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
|
|||||||
default: /* read! */
|
default: /* read! */
|
||||||
if(pfd[0].revents & POLLIN) {
|
if(pfd[0].revents & POLLIN) {
|
||||||
/* read data from network */
|
/* read data from network */
|
||||||
result = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
|
result = Curl_read(conn, sockfd, buf, data->set.buffer_size, &nread);
|
||||||
/* read would've blocked. Loop again */
|
/* read would've blocked. Loop again */
|
||||||
if(result == CURLE_AGAIN)
|
if(result == CURLE_AGAIN)
|
||||||
break;
|
break;
|
||||||
@ -1625,12 +1625,12 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
|
|||||||
nread = 0;
|
nread = 0;
|
||||||
if(poll_cnt == 2) {
|
if(poll_cnt == 2) {
|
||||||
if(pfd[1].revents & POLLIN) { /* read from in file */
|
if(pfd[1].revents & POLLIN) { /* read from in file */
|
||||||
nread = read(pfd[1].fd, buf, BUFSIZE - 1);
|
nread = read(pfd[1].fd, buf, data->set.buffer_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* read from user-supplied method */
|
/* read from user-supplied method */
|
||||||
nread = (int)data->state.fread_func(buf, 1, BUFSIZE - 1,
|
nread = (int)data->state.fread_func(buf, 1, data->set.buffer_size,
|
||||||
data->state.in);
|
data->state.in);
|
||||||
if(nread == CURL_READFUNC_ABORT) {
|
if(nread == CURL_READFUNC_ABORT) {
|
||||||
keepon = FALSE;
|
keepon = FALSE;
|
||||||
|
@ -680,8 +680,6 @@ static CURLcode readwrite_data(struct Curl_easy *data,
|
|||||||
excess = (size_t)(k->bytecount + nread - k->maxdownload);
|
excess = (size_t)(k->bytecount + nread - k->maxdownload);
|
||||||
if(excess > 0 && !k->ignorebody) {
|
if(excess > 0 && !k->ignorebody) {
|
||||||
if(Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1)) {
|
if(Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1)) {
|
||||||
/* The 'excess' amount below can't be more than BUFSIZE which
|
|
||||||
always will fit in a size_t */
|
|
||||||
infof(data,
|
infof(data,
|
||||||
"Rewinding stream by : %zu"
|
"Rewinding stream by : %zu"
|
||||||
" bytes on url %s (size = %" CURL_FORMAT_CURL_OFF_T
|
" bytes on url %s (size = %" CURL_FORMAT_CURL_OFF_T
|
||||||
@ -936,7 +934,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
|||||||
(data->set.crlf))) {
|
(data->set.crlf))) {
|
||||||
/* Do we need to allocate a scratch buffer? */
|
/* Do we need to allocate a scratch buffer? */
|
||||||
if(!data->state.scratch) {
|
if(!data->state.scratch) {
|
||||||
data->state.scratch = malloc(2 * BUFSIZE);
|
data->state.scratch = malloc(2 * data->set.buffer_size);
|
||||||
if(!data->state.scratch) {
|
if(!data->state.scratch) {
|
||||||
failf(data, "Failed to alloc scratch buffer!");
|
failf(data, "Failed to alloc scratch buffer!");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user