aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2022-02-14 14:53:46 +0300
committerRoman Arutyunyan <arut@nginx.com>2022-02-14 14:53:46 +0300
commitf15459fc466b12e3c1591b4d0a06c113f7a591c5 (patch)
tree2afe881d8e877e9d9ed50d6469442e2f631b5963 /src
parent055025fa3b6d42d61ee99d8b6d26a0bf93444e85 (diff)
downloadnginx-f15459fc466b12e3c1591b4d0a06c113f7a591c5.tar.gz
nginx-f15459fc466b12e3c1591b4d0a06c113f7a591c5.zip
QUIC: eliminated ngx_quic_copy_buf().
Its only call is substituted with QUIC buffer write/read pair.
Diffstat (limited to 'src')
-rw-r--r--src/event/quic/ngx_event_quic_frames.c34
-rw-r--r--src/event/quic/ngx_event_quic_frames.h2
-rw-r--r--src/event/quic/ngx_event_quic_ssl.c29
3 files changed, 25 insertions, 40 deletions
diff --git a/src/event/quic/ngx_event_quic_frames.c b/src/event/quic/ngx_event_quic_frames.c
index 4a39141eb..c6d8de74e 100644
--- a/src/event/quic/ngx_event_quic_frames.c
+++ b/src/event/quic/ngx_event_quic_frames.c
@@ -485,40 +485,6 @@ ngx_quic_alloc_chain(ngx_connection_t *c)
ngx_chain_t *
-ngx_quic_copy_buf(ngx_connection_t *c, u_char *data, size_t len)
-{
- size_t n;
- ngx_buf_t *b;
- ngx_chain_t *cl, *out, **ll;
-
- out = NULL;
- ll = &out;
-
- while (len) {
- cl = ngx_quic_alloc_chain(c);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- b = cl->buf;
- n = ngx_min((size_t) (b->end - b->last), len);
-
- b->last = ngx_cpymem(b->last, data, n);
-
- data += n;
- len -= n;
-
- *ll = cl;
- ll = &cl->next;
- }
-
- *ll = NULL;
-
- return out;
-}
-
-
-ngx_chain_t *
ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
ngx_chain_t *in, uint64_t limit, uint64_t offset)
{
diff --git a/src/event/quic/ngx_event_quic_frames.h b/src/event/quic/ngx_event_quic_frames.h
index 48cb22e91..fbff68e5d 100644
--- a/src/event/quic/ngx_event_quic_frames.h
+++ b/src/event/quic/ngx_event_quic_frames.h
@@ -24,8 +24,6 @@ ngx_int_t ngx_quic_split_frame(ngx_connection_t *c, ngx_quic_frame_t *f,
size_t len);
ngx_chain_t *ngx_quic_alloc_chain(ngx_connection_t *c);
-ngx_chain_t *ngx_quic_copy_buf(ngx_connection_t *c, u_char *data,
- size_t len);
void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in);
ngx_chain_t *ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
diff --git a/src/event/quic/ngx_event_quic_ssl.c b/src/event/quic/ngx_event_quic_ssl.c
index 8e01a8742..006566141 100644
--- a/src/event/quic/ngx_event_quic_ssl.c
+++ b/src/event/quic/ngx_event_quic_ssl.c
@@ -183,10 +183,13 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
{
u_char *p, *end;
size_t client_params_len;
+ ngx_buf_t buf;
+ ngx_chain_t *out, cl;
const uint8_t *client_params;
ngx_quic_tp_t ctp;
ngx_quic_frame_t *frame;
ngx_connection_t *c;
+ ngx_quic_buffer_t qb;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
#if defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
@@ -263,16 +266,34 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
ctx = ngx_quic_get_send_ctx(qc, level);
- frame = ngx_quic_alloc_frame(c);
- if (frame == NULL) {
+ ngx_memzero(&buf, sizeof(ngx_buf_t));
+
+ buf.pos = (u_char *) data;
+ buf.last = buf.pos + len;
+ buf.temporary = 1;
+
+ cl.buf = &buf;
+ cl.next = NULL;
+
+ ngx_memzero(&qb, sizeof(ngx_quic_buffer_t));
+
+ if (ngx_quic_write_buffer(c, &qb, &cl, len, 0) == NGX_CHAIN_ERROR) {
return 0;
}
- frame->data = ngx_quic_copy_buf(c, (u_char *) data, len);
- if (frame->data == NGX_CHAIN_ERROR) {
+ out = ngx_quic_read_buffer(c, &qb, len);
+ if (out == NGX_CHAIN_ERROR) {
+ return 0;
+ }
+
+ ngx_quic_free_buffer(c, &qb);
+
+ frame = ngx_quic_alloc_frame(c);
+ if (frame == NULL) {
return 0;
}
+ frame->data = out;
frame->level = level;
frame->type = NGX_QUIC_FT_CRYPTO;
frame->u.crypto.offset = ctx->crypto_sent;