aboutsummaryrefslogtreecommitdiff
path: root/src/http/v3/ngx_http_v3_streams.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/v3/ngx_http_v3_streams.c')
-rw-r--r--src/http/v3/ngx_http_v3_streams.c143
1 files changed, 37 insertions, 106 deletions
diff --git a/src/http/v3/ngx_http_v3_streams.c b/src/http/v3/ngx_http_v3_streams.c
index a20008c19..292e6653b 100644
--- a/src/http/v3/ngx_http_v3_streams.c
+++ b/src/http/v3/ngx_http_v3_streams.c
@@ -10,13 +10,8 @@
#include <ngx_http.h>
-typedef ngx_int_t (*ngx_http_v3_handler_pt)(ngx_connection_t *c, void *data,
- u_char ch);
-
-
typedef struct {
- ngx_http_v3_handler_pt handler;
- void *data;
+ ngx_http_v3_parse_uni_t parse;
ngx_int_t index;
} ngx_http_v3_uni_stream_t;
@@ -32,7 +27,6 @@ typedef struct {
static void ngx_http_v3_keepalive_handler(ngx_event_t *ev);
static void ngx_http_v3_cleanup_session(void *data);
static void ngx_http_v3_close_uni_stream(ngx_connection_t *c);
-static void ngx_http_v3_read_uni_stream_type(ngx_event_t *rev);
static void ngx_http_v3_uni_read_handler(ngx_event_t *rev);
static void ngx_http_v3_dummy_write_handler(ngx_event_t *wev);
static void ngx_http_v3_push_cleanup(void *data);
@@ -131,10 +125,10 @@ ngx_http_v3_init_uni_stream(ngx_connection_t *c)
c->data = us;
- c->read->handler = ngx_http_v3_read_uni_stream_type;
+ c->read->handler = ngx_http_v3_uni_read_handler;
c->write->handler = ngx_http_v3_dummy_write_handler;
- ngx_http_v3_read_uni_stream_type(c->read);
+ ngx_http_v3_uni_read_handler(c->read);
}
@@ -164,118 +158,59 @@ ngx_http_v3_close_uni_stream(ngx_connection_t *c)
}
-static void
-ngx_http_v3_read_uni_stream_type(ngx_event_t *rev)
+ngx_int_t
+ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type)
{
- u_char ch;
- ssize_t n;
- ngx_int_t index, rc;
- ngx_connection_t *c;
+ ngx_int_t index;
ngx_http_v3_session_t *h3c;
ngx_http_v3_uni_stream_t *us;
- c = rev->data;
- us = c->data;
- h3c = ngx_http_v3_get_session(c);
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read stream type");
-
- while (rev->ready) {
-
- n = c->recv(c, &ch, 1);
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- if (n == 0) {
- rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR;
- goto failed;
- }
-
- if (n != 1) {
- rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;
- goto failed;
- }
-
- switch (ch) {
-
- case NGX_HTTP_V3_STREAM_ENCODER:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 encoder stream");
-
- index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER;
- us->handler = ngx_http_v3_parse_encoder;
- n = sizeof(ngx_http_v3_parse_encoder_t);
-
- break;
-
- case NGX_HTTP_V3_STREAM_DECODER:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 decoder stream");
+ switch (type) {
- index = NGX_HTTP_V3_STREAM_CLIENT_DECODER;
- us->handler = ngx_http_v3_parse_decoder;
- n = sizeof(ngx_http_v3_parse_decoder_t);
+ case NGX_HTTP_V3_STREAM_ENCODER:
- break;
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
+ "http3 encoder stream");
+ index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER;
+ break;
- case NGX_HTTP_V3_STREAM_CONTROL:
+ case NGX_HTTP_V3_STREAM_DECODER:
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 control stream");
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
+ "http3 decoder stream");
+ index = NGX_HTTP_V3_STREAM_CLIENT_DECODER;
+ break;
- index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL;
- us->handler = ngx_http_v3_parse_control;
- n = sizeof(ngx_http_v3_parse_control_t);
+ case NGX_HTTP_V3_STREAM_CONTROL:
- break;
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
+ "http3 control stream");
+ index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL;
- default:
+ break;
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 stream 0x%02xi", (ngx_int_t) ch);
- index = -1;
- n = 0;
- }
+ default:
- if (index >= 0) {
- if (h3c->known_streams[index]) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists");
- rc = NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR;
- goto failed;
- }
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
+ "http3 stream 0x%02xL", type);
+ index = -1;
+ }
- us->index = index;
- h3c->known_streams[index] = c;
- }
+ if (index >= 0) {
+ h3c = ngx_http_v3_get_session(c);
- if (n) {
- us->data = ngx_pcalloc(c->pool, n);
- if (us->data == NULL) {
- rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;
- goto failed;
- }
+ if (h3c->known_streams[index]) {
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists");
+ return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR;
}
- rev->handler = ngx_http_v3_uni_read_handler;
- ngx_http_v3_uni_read_handler(rev);
- return;
- }
+ h3c->known_streams[index] = c;
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;
- goto failed;
+ us = c->data;
+ us->index = index;
}
- return;
-
-failed:
-
- ngx_http_v3_finalize_connection(c, rc, "could not read stream type");
- ngx_http_v3_close_uni_stream(c);
+ return NGX_OK;
}
@@ -317,13 +252,9 @@ ngx_http_v3_uni_read_handler(ngx_event_t *rev)
break;
}
- if (us->handler == NULL) {
- continue;
- }
-
for (i = 0; i < n; i++) {
- rc = us->handler(c, us->data, buf[i]);
+ rc = ngx_http_v3_parse_uni(c, &us->parse, buf[i]);
if (rc == NGX_DONE) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,