Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~ #1941

Closed
wants to merge 1 commit into from
Closed

~ #1941

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 49 additions & 15 deletions modules/ngx_http_xquic_module/ngx_http_v3_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void ngx_http_v3_run_request(ngx_http_request_t *r, ngx_http_v3_stream_t
static void ngx_http_v3_stream_free(ngx_http_v3_stream_t *h3_stream);
void ngx_http_v3_stream_cancel(ngx_http_v3_stream_t *h3_stream,
ngx_int_t status);
static void ngx_http_v3_continue_recv_body_handler(ngx_event_t *rev);


static void
Expand Down Expand Up @@ -845,6 +846,24 @@ ngx_http_v3_init_request_body(ngx_http_request_t *r)
}


static void
ngx_http_v3_continue_recv_body_handler(ngx_event_t *rev)
{
ngx_http_request_t *r;
ngx_http_v3_stream_t *stream;
xqc_h3_request_t *h3_request;

stream = rev->data;
r = stream->request;
h3_request = stream->h3_request;

if (ngx_http_v3_recv_body(r, stream, h3_request) != NGX_OK) {
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
"|xquic|ngx_http_v3_continue_recv_body_handler error|");
}
}


ngx_int_t
ngx_http_v3_recv_body(ngx_http_request_t *r,
ngx_http_v3_stream_t *stream,
Expand All @@ -853,11 +872,15 @@ ngx_http_v3_recv_body(ngx_http_request_t *r,
ngx_http_core_loc_conf_t *clcf;
ngx_buf_t *buf;
ngx_int_t rc;
ngx_connection_t *fc;
ngx_connection_t *fc, *c, *pc;
ngx_http_upstream_t *u;
off_t len;

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
fc = r->connection;
c = stream->connection->connection;
u = r->upstream;
pc = u->peer.connection;

/* check if skip data */
if (stream->skip_data) {
Expand Down Expand Up @@ -896,28 +919,39 @@ ngx_http_v3_recv_body(ngx_http_request_t *r,

do {
if (buf->last == buf->end) {
len = buf->end - buf->start;
off_t pos_len = buf->pos - buf->start;

u_char *new_buf = ngx_pcalloc(r->pool, len * 2);
if (new_buf == NULL) {
ngx_log_error(NGX_LOG_WARN, fc->log, 0,
"|xquic|ngx_http_v3_recv_body|ngx_pcalloc error|");
if (r->request_body_no_buffering) {

return NGX_ERROR;
}
pc->write->active = 0;
pc->write->ready = 1;

ngx_memcpy(new_buf, buf->start, len);
buf->pos = new_buf + pos_len;
buf->last = new_buf + len;
buf->end = new_buf + len * 2;
ngx_pfree(r->pool, buf->start);
buf->start = new_buf;
ngx_post_event(pc->write, &ngx_posted_events);

c->read->active = 0;
c->read->ready = 1;
c->read->data = stream;
c->read->handler = ngx_http_v3_continue_recv_body_handler;
ngx_post_event(c->read, &ngx_posted_events);
return NGX_OK;
}
return NGX_ERROR;
}

ngx_log_error(NGX_LOG_DEBUG, fc->log, 0,
"|xquic|ngx_http_v3_recv_body|buf->size:%z|", buf->end - buf->last);

if (pc) {
pc->write->active = 1;
pc->write->ready = 1;
}

if (c && c->read->active == 0) {
c->read->active = 1;
c->read->ready = 0;
c->read->data = c;
c->read->handler = ngx_http_xquic_read_handler;
}

size = xqc_h3_request_recv_body(h3_request, buf->last, buf->end - buf->last, &fin);
if (size == -XQC_EAGAIN) {
break;
Expand Down
8 changes: 5 additions & 3 deletions modules/ngx_http_xquic_module/ngx_http_xquic.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ ngx_http_v3_filter_request_body(ngx_http_request_t *r)
ngx_log_error(NGX_LOG_DEBUG, fc->log, 0,
"|xquic|ngx_http_v3_filter_request_body|size:%O, fin:%O|", buf->last - buf->pos, fin);

if (buf->pos == buf->last && rb->rest) {
if (buf->pos == buf->last && (rb->rest || rb->last_sent)) {
cl = NULL;
goto update;
}
Expand Down Expand Up @@ -682,9 +682,10 @@ ngx_http_v3_filter_request_body(ngx_http_request_t *r)
b->last = buf->last;
b->start = b->pos;
b->end = b->last;

buf->pos = buf->last;
}

buf->pos = buf->last = buf->start;
ngx_log_error(NGX_LOG_DEBUG, fc->log, 0,
"|xquic|ngx_http_v3_filter_request_body|received:%O|", rb->received);

Expand All @@ -701,6 +702,7 @@ ngx_http_v3_filter_request_body(ngx_http_request_t *r)
}

b->last_buf = 1;
rb->last_sent = 1;
}

b->tag = (ngx_buf_tag_t) &ngx_http_v3_filter_request_body;
Expand Down Expand Up @@ -979,7 +981,7 @@ ngx_http_xquic_session_process_packet(ngx_http_xquic_connection_t *qc,
/**
* used to recv udp packets
*/
static void
void
ngx_http_xquic_read_handler(ngx_event_t *rev)
{
ssize_t n;
Expand Down
1 change: 1 addition & 0 deletions modules/ngx_http_xquic_module/ngx_http_xquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ void ngx_http_v3_read_client_request_body_handler(ngx_http_request_t *r);
xqc_int_t ngx_http_v3_cert_cb(const char *sni, void **chain,
void **cert, void **key, void *conn_user_data);

void ngx_http_xquic_read_handler(ngx_event_t *rev);

#endif /* _NGX_HTTP_XQUIC_H_INCLUDED_ */