comparison src/http/v3/ngx_http_v3_streams.c @ 8838:d6e191a583cc quic

HTTP/3: bulk parse functions. Previously HTTP/3 streams were parsed by one character. Now all parse functions receive buffers. This should optimize parsing time and CPU load.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 08 Jul 2021 21:52:47 +0300
parents 054f9be0aaf9
children 531075860fe2
comparison
equal deleted inserted replaced
8837:8f0f6407ae23 8838:d6e191a583cc
166 static void 166 static void
167 ngx_http_v3_uni_read_handler(ngx_event_t *rev) 167 ngx_http_v3_uni_read_handler(ngx_event_t *rev)
168 { 168 {
169 u_char buf[128]; 169 u_char buf[128];
170 ssize_t n; 170 ssize_t n;
171 ngx_int_t rc, i; 171 ngx_buf_t b;
172 ngx_int_t rc;
172 ngx_connection_t *c; 173 ngx_connection_t *c;
173 ngx_http_v3_uni_stream_t *us; 174 ngx_http_v3_uni_stream_t *us;
174 175
175 c = rev->data; 176 c = rev->data;
176 us = c->data; 177 us = c->data;
177 178
178 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler"); 179 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler");
180
181 ngx_memzero(&b, sizeof(ngx_buf_t));
179 182
180 while (rev->ready) { 183 while (rev->ready) {
181 184
182 n = c->recv(c, buf, sizeof(buf)); 185 n = c->recv(c, buf, sizeof(buf));
183 186
199 202
200 if (n == NGX_AGAIN) { 203 if (n == NGX_AGAIN) {
201 break; 204 break;
202 } 205 }
203 206
204 for (i = 0; i < n; i++) { 207 b.pos = buf;
205 208 b.last = buf + n;
206 rc = ngx_http_v3_parse_uni(c, &us->parse, buf[i]); 209
207 210 rc = ngx_http_v3_parse_uni(c, &us->parse, &b);
208 if (rc == NGX_DONE) { 211
209 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 212 if (rc == NGX_DONE) {
210 "http3 read done"); 213 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
211 ngx_http_v3_close_uni_stream(c); 214 "http3 read done");
212 return; 215 ngx_http_v3_close_uni_stream(c);
213 } 216 return;
214 217 }
215 if (rc > 0) { 218
216 goto failed; 219 if (rc > 0) {
217 } 220 goto failed;
218 221 }
219 if (rc != NGX_AGAIN) { 222
220 rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR; 223 if (rc != NGX_AGAIN) {
221 goto failed; 224 rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR;
222 } 225 goto failed;
223 } 226 }
224 } 227 }
225 228
226 if (ngx_handle_read_event(rev, 0) != NGX_OK) { 229 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
227 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; 230 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;