comparison src/http/v3/ngx_http_v3.c @ 8774:f4d3f5d93a82 quic

HTTP/3: moved session initialization to a separate file. Previously it was in ngx_http_v3_streams.c, but it's unrelated to streams.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 05 May 2021 15:15:48 +0300
parents
children 6e2c23481abb
comparison
equal deleted inserted replaced
8773:b43e50f47b2e 8774:f4d3f5d93a82
1
2 /*
3 * Copyright (C) Roman Arutyunyan
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8 #include <ngx_config.h>
9 #include <ngx_core.h>
10 #include <ngx_http.h>
11
12
13 static void ngx_http_v3_keepalive_handler(ngx_event_t *ev);
14 static void ngx_http_v3_cleanup_session(void *data);
15
16
17 ngx_int_t
18 ngx_http_v3_init_session(ngx_connection_t *c)
19 {
20 ngx_connection_t *pc;
21 ngx_pool_cleanup_t *cln;
22 ngx_http_connection_t *hc;
23 ngx_http_v3_session_t *h3c;
24
25 pc = c->quic->parent;
26 hc = pc->data;
27
28 if (hc->v3_session) {
29 return NGX_OK;
30 }
31
32 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init session");
33
34 h3c = ngx_pcalloc(pc->pool, sizeof(ngx_http_v3_session_t));
35 if (h3c == NULL) {
36 return NGX_ERROR;
37 }
38
39 h3c->max_push_id = (uint64_t) -1;
40
41 ngx_queue_init(&h3c->blocked);
42 ngx_queue_init(&h3c->pushing);
43
44 h3c->keepalive.log = pc->log;
45 h3c->keepalive.data = pc;
46 h3c->keepalive.handler = ngx_http_v3_keepalive_handler;
47 h3c->keepalive.cancelable = 1;
48
49 cln = ngx_pool_cleanup_add(pc->pool, 0);
50 if (cln == NULL) {
51 return NGX_ERROR;
52 }
53
54 cln->handler = ngx_http_v3_cleanup_session;
55 cln->data = h3c;
56
57 hc->v3_session = h3c;
58
59 return ngx_http_v3_send_settings(c);
60 }
61
62
63 static void
64 ngx_http_v3_keepalive_handler(ngx_event_t *ev)
65 {
66 ngx_connection_t *c;
67
68 c = ev->data;
69
70 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 keepalive handler");
71
72 ngx_quic_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
73 "keepalive timeout");
74 }
75
76
77 static void
78 ngx_http_v3_cleanup_session(void *data)
79 {
80 ngx_http_v3_session_t *h3c = data;
81
82 if (h3c->keepalive.timer_set) {
83 ngx_del_timer(&h3c->keepalive);
84 }
85 }