mirror of
https://github.com/curl/curl.git
synced 2026-08-26 12:53:35 +03:00
lib: Curl_read/Curl_write clarifications
- replace `Curl_read()`, `Curl_write()` and `Curl_nwrite()` to
clarify when and at what level they operate
- send/recv of transfer related data is now done via
`Curl_xfer_send()/Curl_xfer_recv()` which no longer has
socket/socketindex as parameter. It decides on the transfer
setup of `conn->sockfd` and `conn->writesockfd` on which
connection filter chain to operate.
- send/recv on a specific connection filter chain is done via
`Curl_conn_send()/Curl_conn_recv()` which get the socket index
as parameter.
- rename `Curl_setup_transfer()` to `Curl_xfer_setup()` for
naming consistency
- clarify that the special CURLE_AGAIN hangling to return
`CURLE_OK` with length 0 only applies to `Curl_xfer_send()`
and CURLE_AGAIN is returned by all other send() variants.
- fix a bug in websocket `curl_ws_recv()` that mixed up data
when it arrived in more than a single chunk (to be made
into a sperate PR, also)
Added as documented [in
CLIENT-READER.md](5b1f31dfba/docs/CLIENT-READERS.md).
- old `Curl_buffer_send()` completely replaced by new `Curl_req_send()`
- old `Curl_fillreadbuffer()` replaced with `Curl_client_read()`
- HTTP chunked uploads are now formatted in a client reader added when
needed.
- FTP line-end conversions are done in a client reader added when
needed.
- when sending requests headers, remaining buffer space is filled with
body data for sending in "one go". This is independent of the request
body size. Resolves #12938 as now small and large requests have the
same code path.
Changes done to test cases:
- test513: now fails before sending request headers as this initial
"client read" triggers the setup fault. Behaves now the same as in
hyper build
- test547, test555, test1620: fix the length check in the lib code to
only fail for reads *smaller* than expected. This was a bug in the
test code that never triggered in the old implementation.
Closes #12969
This commit is contained in:
parent
8d67c61c47
commit
9369c30cd8
26 changed files with 1191 additions and 1021 deletions
102
lib/c-hyper.c
102
lib/c-hyper.c
|
|
@ -117,8 +117,6 @@ size_t Curl_hyper_send(void *userp, hyper_context *ctx,
|
|||
DEBUGF(infof(data, "Curl_hyper_send(%zu)", buflen));
|
||||
result = Curl_conn_send(data, io_ctx->sockindex,
|
||||
(void *)buf, buflen, &nwrote);
|
||||
if(!result && !nwrote)
|
||||
result = CURLE_AGAIN;
|
||||
if(result == CURLE_AGAIN) {
|
||||
DEBUGF(infof(data, "Curl_hyper_send(%zu) -> EAGAIN", buflen));
|
||||
/* would block, register interest */
|
||||
|
|
@ -659,48 +657,13 @@ static CURLcode request_target(struct Curl_easy *data,
|
|||
return result;
|
||||
}
|
||||
|
||||
static int uploadpostfields(void *userdata, hyper_context *ctx,
|
||||
hyper_buf **chunk)
|
||||
{
|
||||
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
||||
(void)ctx;
|
||||
if(data->req.exp100 > EXP100_SEND_DATA) {
|
||||
if(data->req.exp100 == EXP100_FAILED)
|
||||
return HYPER_POLL_ERROR;
|
||||
|
||||
/* still waiting confirmation */
|
||||
if(data->hyp.exp100_waker)
|
||||
hyper_waker_free(data->hyp.exp100_waker);
|
||||
data->hyp.exp100_waker = hyper_context_waker(ctx);
|
||||
return HYPER_POLL_PENDING;
|
||||
}
|
||||
if(data->req.upload_done)
|
||||
*chunk = NULL; /* nothing more to deliver */
|
||||
else {
|
||||
/* send everything off in a single go */
|
||||
hyper_buf *copy = hyper_buf_copy(data->set.postfields,
|
||||
(size_t)data->req.p.http->postsize);
|
||||
if(copy)
|
||||
*chunk = copy;
|
||||
else {
|
||||
data->state.hresult = CURLE_OUT_OF_MEMORY;
|
||||
return HYPER_POLL_ERROR;
|
||||
}
|
||||
/* increasing the writebytecount here is a little premature but we
|
||||
don't know exactly when the body is sent */
|
||||
data->req.writebytecount += (size_t)data->req.p.http->postsize;
|
||||
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
|
||||
data->req.upload_done = TRUE;
|
||||
}
|
||||
return HYPER_POLL_READY;
|
||||
}
|
||||
|
||||
static int uploadstreamed(void *userdata, hyper_context *ctx,
|
||||
hyper_buf **chunk)
|
||||
{
|
||||
size_t fillcount;
|
||||
struct Curl_easy *data = (struct Curl_easy *)userdata;
|
||||
CURLcode result;
|
||||
bool eos;
|
||||
(void)ctx;
|
||||
|
||||
if(data->req.exp100 > EXP100_SEND_DATA) {
|
||||
|
|
@ -714,32 +677,15 @@ static int uploadstreamed(void *userdata, hyper_context *ctx,
|
|||
return HYPER_POLL_PENDING;
|
||||
}
|
||||
|
||||
if(data->req.upload_chunky && data->req.authneg) {
|
||||
fillcount = 0;
|
||||
data->req.upload_chunky = FALSE;
|
||||
result = CURLE_OK;
|
||||
}
|
||||
else {
|
||||
result = Curl_fillreadbuffer(data, data->set.upload_buffer_size,
|
||||
&fillcount);
|
||||
}
|
||||
result = Curl_client_read(data, data->state.ulbuf,
|
||||
data->set.upload_buffer_size,
|
||||
&fillcount, &eos);
|
||||
if(result) {
|
||||
data->state.hresult = result;
|
||||
return HYPER_POLL_ERROR;
|
||||
}
|
||||
if(!fillcount) {
|
||||
if((data->req.keepon & KEEP_SEND_PAUSE) != KEEP_SEND_PAUSE)
|
||||
/* done! */
|
||||
*chunk = NULL;
|
||||
else {
|
||||
/* paused, save a waker */
|
||||
if(data->hyp.send_body_waker)
|
||||
hyper_waker_free(data->hyp.send_body_waker);
|
||||
data->hyp.send_body_waker = hyper_context_waker(ctx);
|
||||
return HYPER_POLL_PENDING;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if(fillcount) {
|
||||
hyper_buf *copy = hyper_buf_copy((uint8_t *)data->state.ulbuf, fillcount);
|
||||
if(copy)
|
||||
*chunk = copy;
|
||||
|
|
@ -751,8 +697,19 @@ static int uploadstreamed(void *userdata, hyper_context *ctx,
|
|||
don't know exactly when the body is sent */
|
||||
data->req.writebytecount += fillcount;
|
||||
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
|
||||
return HYPER_POLL_READY;
|
||||
}
|
||||
else if(eos) {
|
||||
*chunk = NULL;
|
||||
return HYPER_POLL_READY;
|
||||
}
|
||||
else {
|
||||
/* paused, save a waker */
|
||||
if(data->hyp.send_body_waker)
|
||||
hyper_waker_free(data->hyp.send_body_waker);
|
||||
data->hyp.send_body_waker = hyper_context_waker(ctx);
|
||||
return HYPER_POLL_PENDING;
|
||||
}
|
||||
return HYPER_POLL_READY;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -773,7 +730,7 @@ static CURLcode bodysend(struct Curl_easy *data,
|
|||
else {
|
||||
hyper_body *body;
|
||||
Curl_dyn_init(&req, DYN_HTTP_REQUEST);
|
||||
result = Curl_http_req_send(data, &req, httpreq);
|
||||
result = Curl_http_req_complete(data, &req, httpreq);
|
||||
|
||||
if(!result)
|
||||
result = Curl_hyper_header(data, headers, Curl_dyn_ptr(&req));
|
||||
|
|
@ -782,18 +739,15 @@ static CURLcode bodysend(struct Curl_easy *data,
|
|||
|
||||
body = hyper_body_new();
|
||||
hyper_body_set_userdata(body, data);
|
||||
if(data->set.postfields)
|
||||
hyper_body_set_data_func(body, uploadpostfields);
|
||||
else {
|
||||
result = Curl_get_upload_buffer(data);
|
||||
if(result) {
|
||||
hyper_body_free(body);
|
||||
return result;
|
||||
}
|
||||
/* init the "upload from here" pointer */
|
||||
data->req.upload_fromhere = data->state.ulbuf;
|
||||
hyper_body_set_data_func(body, uploadstreamed);
|
||||
result = Curl_get_upload_buffer(data);
|
||||
if(result) {
|
||||
hyper_body_free(body);
|
||||
return result;
|
||||
}
|
||||
/* init the "upload from here" pointer */
|
||||
data->req.upload_fromhere = data->state.ulbuf;
|
||||
hyper_body_set_data_func(body, uploadstreamed);
|
||||
|
||||
if(HYPERE_OK != hyper_request_set_body(hyperreq, body)) {
|
||||
/* fail */
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
|
|
@ -888,7 +842,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
|||
may be parts of the request that is not yet sent, since we can deal with
|
||||
the rest of the request in the PERFORM phase. */
|
||||
*done = TRUE;
|
||||
Curl_cw_reset(data);
|
||||
Curl_client_reset(data);
|
||||
|
||||
/* Add collecting of headers written to client. For a new connection,
|
||||
* we might have done that already, but reuse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue