mirror of
https://github.com/curl/curl.git
synced 2026-08-26 10:43:32 +03:00
cf-socket: improvements in socket I/O handling
- Curl_write_plain/Curl_read_plain have been eliminated. Last code use now uses Curl_conn_send/recv so that requests use conn->send/revc callbacks which defaults to cfilters use. - Curl_recv_plain/Curl_send_plain have been internalized in cf-socket.c. - USE_RECV_BEFORE_SEND_WORKAROUND (active on Windows) has been moved into cf-socket.c. The pre_recv buffer is held at the socket filter context. `postponed_data` structures have been removed from `connectdata`. - the hanger in HTTP/2 request handling was a result of read buffering on all sends and the multi handling is not prepared for this. The following happens: - multi preforms on a HTTP/2 easy handle - h2 reads and processes data - this leads to a send of h2 data - which receives and buffers before the send - h2 returns - multi selects on the socket, but no data arrives (its in the buffer already) the workaround now receives data in a loop as long as there is something in the buffer. The real fix would be for multi to change, so that `data_pending` is evaluated before deciding to wait on the socket. io_buffer, optional, in cf-socket.c, http/2 sets state.drain if lower filter have pending data. This io_buffer is only available/used when the -DUSE_RECV_BEFORE_SEND_WORKAROUND is active, e.g. on Windows configurations. It also maintains the original checks on protocol handler being HTTP and conn->send/recv not being replaced. The HTTP/2 (nghttp2) cfilter now sets data->state.drain when it finds out that the "lower" filter chain has still pending data at the end of its IO operation. This prevents the processing from becoming stalled. Closes #10280
This commit is contained in:
parent
a3bcfab4b5
commit
5651a36d1a
14 changed files with 402 additions and 572 deletions
15
lib/http2.c
15
lib/http2.c
|
|
@ -1786,8 +1786,7 @@ static ssize_t h2_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|||
if(ctx->inbuflen == 0) {
|
||||
/* Receive data from the "lower" filters */
|
||||
nread = Curl_conn_cf_recv(cf->next, data, ctx->inbuf, H2_BUFSIZE, err);
|
||||
|
||||
if(nread == -1) {
|
||||
if(nread < 0) {
|
||||
if(*err != CURLE_AGAIN)
|
||||
failf(data, "Failed receiving HTTP2 data");
|
||||
else if(stream->closed)
|
||||
|
|
@ -1796,8 +1795,7 @@ static ssize_t h2_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(nread == 0) {
|
||||
else if(nread == 0) {
|
||||
if(!stream->closed) {
|
||||
/* This will happen when the server or proxy server is SIGKILLed
|
||||
during data transfer. We should emit an error since our data
|
||||
|
|
@ -1814,21 +1812,22 @@ static ssize_t h2_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
H2BUGF(infof(data, "nread=%zd", nread));
|
||||
|
||||
H2BUGF(infof(data, "http2_recv: recvd %zd bytes", nread));
|
||||
ctx->inbuflen = nread;
|
||||
|
||||
DEBUGASSERT(ctx->nread_inbuf == 0);
|
||||
}
|
||||
else {
|
||||
nread = ctx->inbuflen - ctx->nread_inbuf;
|
||||
(void)nread; /* silence warning, used in debug */
|
||||
H2BUGF(infof(data, "Use data left in connection buffer, nread=%zd",
|
||||
nread));
|
||||
}
|
||||
|
||||
if(h2_process_pending_input(cf, data, err))
|
||||
return -1;
|
||||
if(Curl_conn_cf_data_pending(cf->next, data)) {
|
||||
H2BUGF(infof(data, "conn has pending data, set drain"));
|
||||
drain_this(cf, data);
|
||||
}
|
||||
}
|
||||
if(stream->memlen) {
|
||||
ssize_t retlen = stream->memlen;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue