hyper: implement unpausing via client reader

Just a tidy up to contain 'ifdef' pollution of common
code parts with implementation specifics.

- remove the ifdef hyper unpausing in easy.c
- add hyper client reader for CURL_CR_PROTOCOL phase
  that implements the unpause method for calling
  the hyper waker if it is set

Closes #13075
This commit is contained in:
Stefan Eissing 2024-03-07 10:08:35 +01:00 committed by Daniel Stenberg
parent 8a9fbd6291
commit 2c0f2e8163
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
5 changed files with 75 additions and 19 deletions

View File

@ -67,6 +67,9 @@
#include "curl_memory.h"
#include "memdebug.h"
static CURLcode cr_hyper_add(struct Curl_easy *data);
typedef enum {
USERDATA_NOT_SET = 0, /* for tasks with no userdata set; must be zero */
USERDATA_RESP_BODY
@ -718,14 +721,12 @@ out:
}
/*
* bodysend() sets up headers in the outgoing request for an HTTP transfer that
* sends a body
* finalize_request() sets up last headers and optional body settings
*/
static CURLcode bodysend(struct Curl_easy *data,
hyper_headers *headers,
hyper_request *hyperreq,
Curl_HttpReq httpreq)
static CURLcode finalize_request(struct Curl_easy *data,
hyper_headers *headers,
hyper_request *hyperreq,
Curl_HttpReq httpreq)
{
CURLcode result = CURLE_OK;
struct dynbuf req;
@ -757,7 +758,8 @@ static CURLcode bodysend(struct Curl_easy *data,
result = CURLE_OUT_OF_MEMORY;
}
}
return result;
return cr_hyper_add(data);
}
static CURLcode cookies(struct Curl_easy *data,
@ -1127,7 +1129,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
if(result)
goto error;
result = bodysend(data, headers, req, httpreq);
result = finalize_request(data, headers, req, httpreq);
if(result)
goto error;
@ -1212,6 +1214,50 @@ void Curl_hyper_done(struct Curl_easy *data)
hyper_waker_free(h->exp100_waker);
h->exp100_waker = NULL;
}
if(h->send_body_waker) {
hyper_waker_free(h->send_body_waker);
h->send_body_waker = NULL;
}
}
static CURLcode cr_hyper_unpause(struct Curl_easy *data,
struct Curl_creader *reader)
{
(void)reader;
if(data->hyp.send_body_waker) {
hyper_waker_wake(data->hyp.send_body_waker);
data->hyp.send_body_waker = NULL;
}
return CURLE_OK;
}
/* Hyper client reader, handling unpausing */
static const struct Curl_crtype cr_hyper_protocol = {
"cr-hyper",
Curl_creader_def_init,
Curl_creader_def_read,
Curl_creader_def_close,
Curl_creader_def_needs_rewind,
Curl_creader_def_total_length,
Curl_creader_def_resume_from,
Curl_creader_def_rewind,
cr_hyper_unpause,
sizeof(struct Curl_creader)
};
static CURLcode cr_hyper_add(struct Curl_easy *data)
{
struct Curl_creader *reader = NULL;
CURLcode result;
result = Curl_creader_create(&reader, data, &cr_hyper_protocol,
CURL_CR_PROTOCOL);
if(!result)
result = Curl_creader_add(data, reader);
if(result && reader)
Curl_creader_free(data, reader);
return result;
}
#endif /* !defined(CURL_DISABLE_HTTP) && defined(USE_HYPER) */

View File

@ -1126,16 +1126,6 @@ CURLcode curl_easy_pause(struct Curl_easy *data, int action)
return result;
}
#ifdef USE_HYPER
if(!(newstate & KEEP_SEND_PAUSE)) {
/* need to wake the send body waker */
if(data->hyp.send_body_waker) {
hyper_waker_wake(data->hyp.send_body_waker);
data->hyp.send_body_waker = NULL;
}
}
#endif
/* if there's no error and we're not pausing both directions, we want
to have this handle checked soon */
if((newstate & (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=

View File

@ -523,6 +523,21 @@ void Curl_creader_def_close(struct Curl_easy *data,
(void)reader;
}
CURLcode Curl_creader_def_read(struct Curl_easy *data,
struct Curl_creader *reader,
char *buf, size_t blen,
size_t *nread, bool *eos)
{
if(reader->next)
return reader->next->crt->do_read(data, reader->next, buf, blen,
nread, eos);
else {
*nread = 0;
*eos = FALSE;
return CURLE_READ_ERROR;
}
}
bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
struct Curl_creader *reader)
{

View File

@ -241,6 +241,10 @@ CURLcode Curl_creader_def_init(struct Curl_easy *data,
struct Curl_creader *reader);
void Curl_creader_def_close(struct Curl_easy *data,
struct Curl_creader *reader);
CURLcode Curl_creader_def_read(struct Curl_easy *data,
struct Curl_creader *reader,
char *buf, size_t blen,
size_t *nread, bool *eos);
bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
struct Curl_creader *reader);
curl_off_t Curl_creader_def_total_length(struct Curl_easy *data,

View File

@ -46,6 +46,7 @@ my %wl = (
'Curl_xfer_write_resp' => 'internal api',
'Curl_creader_def_init' => 'internal api',
'Curl_creader_def_close' => 'internal api',
'Curl_creader_def_read' => 'internal api',
'Curl_creader_def_total_length' => 'internal api',
);