Newer
Older
* Curl_setup_transfer() is called to setup some basic properties for the
* upcoming transfer.
Curl_setup_transfer(
Daniel Stenberg
committed
struct connectdata *conn, /* connection data */
int sockindex, /* socket index to read from or -1 */
curl_off_t size, /* -1 if unknown at this point */
bool getheader, /* TRUE if header parsing is wanted */
curl_off_t *bytecountp, /* return number of bytes read or NULL */
int writesockindex, /* socket index to write to, it may very well be
the same we read from. -1 disables */
curl_off_t *writecountp /* return number of bytes written or NULL */
)
struct SessionHandle *data;
Daniel Stenberg
committed
struct SingleRequest *k;
Daniel Stenberg
committed
DEBUGASSERT(conn != NULL);
data = conn->data;
Daniel Stenberg
committed
k = &data->req;
DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
/* now copy all input parameters */
conn->sockfd = sockindex == -1 ?
CURL_SOCKET_BAD : conn->sock[sockindex];
conn->writesockfd = writesockindex == -1 ?
CURL_SOCKET_BAD:conn->sock[writesockindex];
Daniel Stenberg
committed
k->getheader = getheader;
Daniel Stenberg
committed
k->size = size;
k->bytecountp = bytecountp;
k->writebytecountp = writecountp;
Daniel Stenberg
committed
/* The code sequence below is placed in this function just because all
necessary input is not always known in do_complete() as this function may
be called after that */
Daniel Stenberg
committed
if(!k->getheader) {
Daniel Stenberg
committed
k->header = FALSE;
Daniel Stenberg
committed
if(size > 0)
Curl_pgrsSetDownloadSize(data, size);
Daniel Stenberg
committed
}
/* we want header and/or body, if neither then don't do this! */
Daniel Stenberg
committed
if(k->getheader || !data->set.opt_no_body) {
Daniel Stenberg
committed
if(conn->sockfd != CURL_SOCKET_BAD) {
k->keepon |= KEEP_RECV;
Daniel Stenberg
committed
}
if(conn->writesockfd != CURL_SOCKET_BAD) {
/* HTTP 1.1 magic:
Even if we require a 100-return code before uploading data, we might
need to write data before that since the REQUEST may not have been
finished sent off just yet.
Thus, we must check if the request has been sent before we set the
state info where we wait for the 100-return code
*/
if((data->state.expect100header) &&
(data->state.proto.http->sending == HTTPSEND_BODY)) {
Daniel Stenberg
committed
/* wait with write until we either got 100-continue or a timeout */
k->exp100 = EXP100_AWAITING_CONTINUE;
Daniel Stenberg
committed
k->start100 = k->start;
}
else {
if(data->state.expect100header)
/* when we've sent off the rest of the headers, we must await a
100-continue but first finish sending the request */
k->exp100 = EXP100_SENDING_REQUEST;
/* enable the write bit when we're not waiting for continue */
k->keepon |= KEEP_SEND;
Daniel Stenberg
committed
}
} /* if(conn->writesockfd != CURL_SOCKET_BAD) */
} /* if(k->getheader || !data->set.opt_no_body) */
Daniel Stenberg
committed
return CURLE_OK;