mirror of
https://github.com/curl/curl.git
synced 2025-09-19 18:42:42 +03:00
transfer: remove 'uploadbuf' pointer and cleanup readwrite_upload()
The data->req.uploadbuf struct member served no good purpose, instead we use ->state.uploadbuffer directly. It makes it clearer in the code which buffer that's being used. Removed the 'SingleRequest *' argument from the readwrite_upload() proto as it can be derived from the Curl_easy struct. Also made the code in the readwrite_upload() function use the 'k->' shortcut to all references to struct fields in 'data->req', which previously was made with a mix of both.
This commit is contained in:
parent
338f427a24
commit
e698b82287
|
@ -853,7 +853,6 @@ static CURLcode done_sending(struct connectdata *conn,
|
||||||
*/
|
*/
|
||||||
static CURLcode readwrite_upload(struct Curl_easy *data,
|
static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
struct connectdata *conn,
|
struct connectdata *conn,
|
||||||
struct SingleRequest *k,
|
|
||||||
int *didwhat)
|
int *didwhat)
|
||||||
{
|
{
|
||||||
ssize_t i, si;
|
ssize_t i, si;
|
||||||
|
@ -861,6 +860,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
CURLcode result;
|
CURLcode result;
|
||||||
ssize_t nread; /* number of bytes read */
|
ssize_t nread; /* number of bytes read */
|
||||||
bool sending_http_headers = FALSE;
|
bool sending_http_headers = FALSE;
|
||||||
|
struct SingleRequest *k = &data->req;
|
||||||
|
|
||||||
if((k->bytecount == 0) && (k->writebytecount == 0))
|
if((k->bytecount == 0) && (k->writebytecount == 0))
|
||||||
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
|
||||||
|
@ -871,15 +871,15 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
|
|
||||||
/* only read more data if there's no upload data already
|
/* only read more data if there's no upload data already
|
||||||
present in the upload buffer */
|
present in the upload buffer */
|
||||||
if(0 == data->req.upload_present) {
|
if(0 == k->upload_present) {
|
||||||
/* init the "upload from here" pointer */
|
/* init the "upload from here" pointer */
|
||||||
data->req.upload_fromhere = k->uploadbuf;
|
k->upload_fromhere = data->state.uploadbuffer;
|
||||||
|
|
||||||
if(!k->upload_done) {
|
if(!k->upload_done) {
|
||||||
/* HTTP pollution, this should be written nicer to become more
|
/* HTTP pollution, this should be written nicer to become more
|
||||||
protocol agnostic. */
|
protocol agnostic. */
|
||||||
int fillcount;
|
int fillcount;
|
||||||
struct HTTP *http = data->req.protop;
|
struct HTTP *http = k->protop;
|
||||||
|
|
||||||
if((k->exp100 == EXP100_SENDING_REQUEST) &&
|
if((k->exp100 == EXP100_SENDING_REQUEST) &&
|
||||||
(http->sending == HTTPSEND_BODY)) {
|
(http->sending == HTTPSEND_BODY)) {
|
||||||
|
@ -926,7 +926,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store number of bytes available for upload */
|
/* store number of bytes available for upload */
|
||||||
data->req.upload_present = nread;
|
k->upload_present = nread;
|
||||||
|
|
||||||
/* convert LF to CRLF if so asked */
|
/* convert LF to CRLF if so asked */
|
||||||
if((!sending_http_headers) && (
|
if((!sending_http_headers) && (
|
||||||
|
@ -952,7 +952,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
* must be used instead of the escape sequences \r & \n.
|
* must be used instead of the escape sequences \r & \n.
|
||||||
*/
|
*/
|
||||||
for(i = 0, si = 0; i < nread; i++, si++) {
|
for(i = 0, si = 0; i < nread; i++, si++) {
|
||||||
if(data->req.upload_fromhere[i] == 0x0a) {
|
if(k->upload_fromhere[i] == 0x0a) {
|
||||||
data->state.scratch[si++] = 0x0d;
|
data->state.scratch[si++] = 0x0d;
|
||||||
data->state.scratch[si] = 0x0a;
|
data->state.scratch[si] = 0x0a;
|
||||||
if(!data->set.crlf) {
|
if(!data->set.crlf) {
|
||||||
|
@ -963,7 +963,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
data->state.scratch[si] = data->req.upload_fromhere[i];
|
data->state.scratch[si] = k->upload_fromhere[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(si != nread) {
|
if(si != nread) {
|
||||||
|
@ -972,10 +972,10 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
nread = si;
|
nread = si;
|
||||||
|
|
||||||
/* upload from the new (replaced) buffer instead */
|
/* upload from the new (replaced) buffer instead */
|
||||||
data->req.upload_fromhere = data->state.scratch;
|
k->upload_fromhere = data->state.scratch;
|
||||||
|
|
||||||
/* set the new amount too */
|
/* set the new amount too */
|
||||||
data->req.upload_present = nread;
|
k->upload_present = nread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,7 +986,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif /* CURL_DISABLE_SMTP */
|
#endif /* CURL_DISABLE_SMTP */
|
||||||
} /* if 0 == data->req.upload_present */
|
} /* if 0 == k->upload_present */
|
||||||
else {
|
else {
|
||||||
/* We have a partial buffer left from a previous "round". Use
|
/* We have a partial buffer left from a previous "round". Use
|
||||||
that instead of reading more data */
|
that instead of reading more data */
|
||||||
|
@ -994,17 +994,17 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
|
|
||||||
/* write to socket (send away data) */
|
/* write to socket (send away data) */
|
||||||
result = Curl_write(conn,
|
result = Curl_write(conn,
|
||||||
conn->writesockfd, /* socket to send to */
|
conn->writesockfd, /* socket to send to */
|
||||||
data->req.upload_fromhere, /* buffer pointer */
|
k->upload_fromhere, /* buffer pointer */
|
||||||
data->req.upload_present, /* buffer size */
|
k->upload_present, /* buffer size */
|
||||||
&bytes_written); /* actually sent */
|
&bytes_written); /* actually sent */
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
if(data->set.verbose)
|
if(data->set.verbose)
|
||||||
/* show the data before we change the pointer upload_fromhere */
|
/* show the data before we change the pointer upload_fromhere */
|
||||||
Curl_debug(data, CURLINFO_DATA_OUT, data->req.upload_fromhere,
|
Curl_debug(data, CURLINFO_DATA_OUT, k->upload_fromhere,
|
||||||
(size_t)bytes_written, conn);
|
(size_t)bytes_written, conn);
|
||||||
|
|
||||||
k->writebytecount += bytes_written;
|
k->writebytecount += bytes_written;
|
||||||
|
@ -1015,20 +1015,20 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
|
||||||
infof(data, "We are completely uploaded and fine\n");
|
infof(data, "We are completely uploaded and fine\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->req.upload_present != bytes_written) {
|
if(k->upload_present != bytes_written) {
|
||||||
/* we only wrote a part of the buffer (if anything), deal with it! */
|
/* we only wrote a part of the buffer (if anything), deal with it! */
|
||||||
|
|
||||||
/* store the amount of bytes left in the buffer to write */
|
/* store the amount of bytes left in the buffer to write */
|
||||||
data->req.upload_present -= bytes_written;
|
k->upload_present -= bytes_written;
|
||||||
|
|
||||||
/* advance the pointer where to find the buffer when the next send
|
/* advance the pointer where to find the buffer when the next send
|
||||||
is to happen */
|
is to happen */
|
||||||
data->req.upload_fromhere += bytes_written;
|
k->upload_fromhere += bytes_written;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* we've uploaded that buffer now */
|
/* we've uploaded that buffer now */
|
||||||
data->req.upload_fromhere = k->uploadbuf;
|
k->upload_fromhere = data->state.uploadbuffer;
|
||||||
data->req.upload_present = 0; /* no more bytes left */
|
k->upload_present = 0; /* no more bytes left */
|
||||||
|
|
||||||
if(k->upload_done) {
|
if(k->upload_done) {
|
||||||
result = done_sending(conn, k);
|
result = done_sending(conn, k);
|
||||||
|
@ -1108,7 +1108,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||||
if((k->keepon & KEEP_SEND) && (select_res & CURL_CSELECT_OUT)) {
|
if((k->keepon & KEEP_SEND) && (select_res & CURL_CSELECT_OUT)) {
|
||||||
/* write */
|
/* write */
|
||||||
|
|
||||||
result = readwrite_upload(data, conn, k, &didwhat);
|
result = readwrite_upload(data, conn, &didwhat);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1186,15 +1186,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
|
||||||
*/
|
*/
|
||||||
(k->bytecount != (k->size + data->state.crlf_conversions)) &&
|
(k->bytecount != (k->size + data->state.crlf_conversions)) &&
|
||||||
#endif /* CURL_DO_LINEEND_CONV */
|
#endif /* CURL_DO_LINEEND_CONV */
|
||||||
!data->req.newurl) {
|
!k->newurl) {
|
||||||
failf(data, "transfer closed with %" CURL_FORMAT_CURL_OFF_T
|
failf(data, "transfer closed with %" CURL_FORMAT_CURL_OFF_T
|
||||||
" bytes remaining to read",
|
" bytes remaining to read", k->size - k->bytecount);
|
||||||
k->size - k->bytecount);
|
|
||||||
return CURLE_PARTIAL_FILE;
|
return CURLE_PARTIAL_FILE;
|
||||||
}
|
}
|
||||||
if(!(data->set.opt_no_body) &&
|
if(!(data->set.opt_no_body) && k->chunk &&
|
||||||
k->chunk &&
|
(conn->chunk.state != CHUNK_STOP)) {
|
||||||
(conn->chunk.state != CHUNK_STOP)) {
|
|
||||||
/*
|
/*
|
||||||
* In chunked mode, return an error if the connection is closed prior to
|
* In chunked mode, return an error if the connection is closed prior to
|
||||||
* the empty (terminating) chunk is read.
|
* the empty (terminating) chunk is read.
|
||||||
|
|
|
@ -6961,7 +6961,6 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
|
||||||
k->bytecount = 0;
|
k->bytecount = 0;
|
||||||
|
|
||||||
k->buf = data->state.buffer;
|
k->buf = data->state.buffer;
|
||||||
k->uploadbuf = data->state.uploadbuffer;
|
|
||||||
k->hbufp = data->state.headerbuff;
|
k->hbufp = data->state.headerbuff;
|
||||||
k->ignorebody=FALSE;
|
k->ignorebody=FALSE;
|
||||||
|
|
||||||
|
|
|
@ -721,7 +721,6 @@ struct SingleRequest {
|
||||||
long bodywrites;
|
long bodywrites;
|
||||||
|
|
||||||
char *buf;
|
char *buf;
|
||||||
char *uploadbuf;
|
|
||||||
curl_socket_t maxfd;
|
curl_socket_t maxfd;
|
||||||
|
|
||||||
int keepon;
|
int keepon;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user