diff options
author | Vladimir Homutov <vl@nginx.com> | 2020-03-12 16:54:43 +0300 |
---|---|---|
committer | Vladimir Homutov <vl@nginx.com> | 2020-03-12 16:54:43 +0300 |
commit | 4f4f56f013eb0dbe5eb66bb2f22584aec26b13e6 (patch) | |
tree | 2acd535245231df1dd49ca9759ba5c45a4787412 /src/http/ngx_http_request.c | |
parent | 6bf6635d86c5e868699b45fc0f68d4bcf6a9b770 (diff) | |
download | nginx-4f4f56f013eb0dbe5eb66bb2f22584aec26b13e6.tar.gz nginx-4f4f56f013eb0dbe5eb66bb2f22584aec26b13e6.zip |
HTTP/QUIC interface reworked.
- events handling moved into src/event/ngx_event_quic.c
- http invokes once ngx_quic_run() and passes stream callback
(diff to original http_request.c is now minimal)
- streams are stored in rbtree using ID as a key
- when a new stream is registered, appropriate callback is called
- ngx_quic_stream_t type represents STREAM and stored in c->qs
Diffstat (limited to 'src/http/ngx_http_request.c')
-rw-r--r-- | src/http/ngx_http_request.c | 105 |
1 files changed, 18 insertions, 87 deletions
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 6d89fef24..7a2c78046 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -62,11 +62,9 @@ static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, #if (NGX_HTTP_SSL) static void ngx_http_ssl_handshake(ngx_event_t *rev); static void ngx_http_ssl_handshake_handler(ngx_connection_t *c); - -static void ngx_http_quic_handshake(ngx_event_t *rev); -static void ngx_http_quic_handshake_handler(ngx_event_t *rev); #endif +static void ngx_http_quic_stream_handler(ngx_connection_t *c); static char *ngx_http_client_errors[] = { @@ -333,9 +331,15 @@ ngx_http_init_connection(ngx_connection_t *c) #if (NGX_HTTP_SSL) if (hc->addr_conf->http3) { + ngx_http_ssl_srv_conf_t *sscf; + hc->quic = 1; - c->log->action = "QUIC handshaking"; - rev->handler = ngx_http_quic_handshake; + + sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module); + + ngx_quic_run(c, &sscf->ssl, c->listening->post_accept_timeout, + ngx_http_quic_stream_handler); + return; } #endif @@ -387,6 +391,15 @@ ngx_http_init_connection(ngx_connection_t *c) static void +ngx_http_quic_stream_handler(ngx_connection_t *c) +{ + ngx_quic_stream_t *qs = c->qs; + + printf("quic stream: 0x%lx\n", qs->id); +} + + +static void ngx_http_wait_request_handler(ngx_event_t *rev) { u_char *p; @@ -401,10 +414,6 @@ ngx_http_wait_request_handler(ngx_event_t *rev) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler"); - if (c->shared) { - goto request; - } - if (rev->timedout) { ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); ngx_http_close_connection(c); @@ -505,8 +514,6 @@ ngx_http_wait_request_handler(ngx_event_t *rev) } } -request: - c->log->action = "reading client request line"; ngx_reusable_connection(c, 0); @@ -659,82 +666,6 @@ ngx_http_alloc_request(ngx_connection_t *c) #if (NGX_HTTP_SSL) static void -ngx_http_quic_handshake(ngx_event_t *rev) -{ - ngx_connection_t *c; - ngx_http_connection_t *hc; - ngx_http_ssl_srv_conf_t *sscf; - - ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "quic handshake"); - - c = rev->data; - hc = c->data; - - sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module); - - if (ngx_quic_input(c, &sscf->ssl, c->buffer) != NGX_OK) { - ngx_http_close_connection(c); - return; - } - - if (!rev->timer_set) { - ngx_add_timer(rev, c->listening->post_accept_timeout); - } - - rev->handler = ngx_http_quic_handshake_handler; - return; -} - - -static void -ngx_http_quic_handshake_handler(ngx_event_t *rev) -{ - ssize_t n; - ngx_connection_t *c; - u_char buf[512]; - ngx_buf_t b; - - b.start = buf; - b.end = buf + 512; - b.pos = b.last = b.start; - - c = rev->data; - - ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "quic handshake handler"); - - if (rev->timedout) { - ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); - ngx_http_close_connection(c); - return; - } - - if (c->close) { - ngx_http_close_connection(c); - return; - } - - n = c->recv(c, b.start, b.end - b.start); - - if (n == NGX_AGAIN) { - return; - } - - if (n == NGX_ERROR) { - c->read->eof = 1; - ngx_http_close_connection(c); - return; - } - - b.last += n; - - if (ngx_quic_input(c, NULL, &b) != NGX_OK) { - ngx_http_close_connection(c); - return; - } -} - - -static void ngx_http_ssl_handshake(ngx_event_t *rev) { u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER + 1]; |