Skip to content

Commit 38854cf

Browse files
authored
Merge pull request #453 from ngtcp2/eliminate-aux
Move aux objects into the individual frames
2 parents bac3594 + ce75e28 commit 38854cf

File tree

5 files changed

+75
-86
lines changed

5 files changed

+75
-86
lines changed

lib/nghttp3_conn.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn,
21422142

21432143
int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
21442144
nghttp3_stream *stream;
2145-
nghttp3_frame_entry frent;
2145+
nghttp3_frame fr;
21462146
int rv;
21472147

21482148
assert(stream_id >= 0);
@@ -2168,23 +2168,25 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
21682168
return rv;
21692169
}
21702170

2171-
frent.fr.settings.type = NGHTTP3_FRAME_SETTINGS;
2172-
frent.aux.settings.local_settings = &conn->local.settings;
2171+
fr.settings = (nghttp3_frame_settings){
2172+
.type = NGHTTP3_FRAME_SETTINGS,
2173+
.local_settings = &conn->local.settings,
2174+
};
21732175

2174-
rv = nghttp3_stream_frq_add(stream, &frent);
2176+
rv = nghttp3_stream_frq_add(stream, &fr);
21752177
if (rv != 0) {
21762178
return rv;
21772179
}
21782180

21792181
if (conn->local.settings.origin_list) {
21802182
assert(conn->server);
21812183

2182-
frent.fr.origin = (nghttp3_frame_origin){
2184+
fr.origin = (nghttp3_frame_origin){
21832185
.type = NGHTTP3_FRAME_ORIGIN,
21842186
.origin_list = *conn->local.settings.origin_list,
21852187
};
21862188

2187-
rv = nghttp3_stream_frq_add(stream, &frent);
2189+
rv = nghttp3_stream_frq_add(stream, &fr);
21882190
if (rv != 0) {
21892191
return rv;
21902192
}
@@ -2414,32 +2416,32 @@ static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream,
24142416
const nghttp3_data_reader *dr) {
24152417
int rv;
24162418
nghttp3_nv *nnva;
2417-
nghttp3_frame_entry frent;
2419+
nghttp3_frame fr;
24182420

24192421
rv = nghttp3_nva_copy(&nnva, nva, nvlen, conn->mem);
24202422
if (rv != 0) {
24212423
return rv;
24222424
}
24232425

2424-
frent.fr.headers = (nghttp3_frame_headers){
2426+
fr.headers = (nghttp3_frame_headers){
24252427
.type = NGHTTP3_FRAME_HEADERS,
24262428
.nva = nnva,
24272429
.nvlen = nvlen,
24282430
};
24292431

2430-
rv = nghttp3_stream_frq_add(stream, &frent);
2432+
rv = nghttp3_stream_frq_add(stream, &fr);
24312433
if (rv != 0) {
24322434
nghttp3_nva_del(nnva, conn->mem);
24332435
return rv;
24342436
}
24352437

24362438
if (dr) {
2437-
frent.fr.data = (nghttp3_frame_data){
2439+
fr.data = (nghttp3_frame_data){
24382440
.type = NGHTTP3_FRAME_DATA,
2441+
.dr = *dr,
24392442
};
2440-
frent.aux.data.dr = *dr;
24412443

2442-
rv = nghttp3_stream_frq_add(stream, &frent);
2444+
rv = nghttp3_stream_frq_add(stream, &fr);
24432445
if (rv != 0) {
24442446
return rv;
24452447
}
@@ -2585,51 +2587,51 @@ int nghttp3_conn_submit_trailers(nghttp3_conn *conn, int64_t stream_id,
25852587
}
25862588

25872589
int nghttp3_conn_submit_shutdown_notice(nghttp3_conn *conn) {
2588-
nghttp3_frame_entry frent;
2590+
nghttp3_frame fr;
25892591
int rv;
25902592

25912593
assert(conn->tx.ctrl);
25922594

2593-
frent.fr.goaway = (nghttp3_frame_goaway){
2595+
fr.goaway = (nghttp3_frame_goaway){
25942596
.type = NGHTTP3_FRAME_GOAWAY,
25952597
.id = conn->server ? NGHTTP3_SHUTDOWN_NOTICE_STREAM_ID
25962598
: NGHTTP3_SHUTDOWN_NOTICE_PUSH_ID,
25972599
};
25982600

2599-
assert(frent.fr.goaway.id <= conn->tx.goaway_id);
2601+
assert(fr.goaway.id <= conn->tx.goaway_id);
26002602

2601-
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &frent);
2603+
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
26022604
if (rv != 0) {
26032605
return rv;
26042606
}
26052607

2606-
conn->tx.goaway_id = frent.fr.goaway.id;
2608+
conn->tx.goaway_id = fr.goaway.id;
26072609
conn->flags |= NGHTTP3_CONN_FLAG_GOAWAY_QUEUED;
26082610

26092611
return 0;
26102612
}
26112613

26122614
int nghttp3_conn_shutdown(nghttp3_conn *conn) {
2613-
nghttp3_frame_entry frent;
2615+
nghttp3_frame fr;
26142616
int rv;
26152617

26162618
assert(conn->tx.ctrl);
26172619

2618-
frent.fr.goaway = (nghttp3_frame_goaway){
2620+
fr.goaway = (nghttp3_frame_goaway){
26192621
.type = NGHTTP3_FRAME_GOAWAY,
26202622
.id = conn->server ? nghttp3_min_int64((1ll << 62) - 4,
26212623
conn->rx.max_stream_id_bidi + 4)
26222624
: 0,
26232625
};
26242626

2625-
assert(frent.fr.goaway.id <= conn->tx.goaway_id);
2627+
assert(fr.goaway.id <= conn->tx.goaway_id);
26262628

2627-
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &frent);
2629+
rv = nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
26282630
if (rv != 0) {
26292631
return rv;
26302632
}
26312633

2632-
conn->tx.goaway_id = frent.fr.goaway.id;
2634+
conn->tx.goaway_id = fr.goaway.id;
26332635
conn->flags |=
26342636
NGHTTP3_CONN_FLAG_GOAWAY_QUEUED | NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED;
26352637

@@ -2870,7 +2872,7 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
28702872
const uint8_t *data,
28712873
size_t datalen) {
28722874
nghttp3_stream *stream;
2873-
nghttp3_frame_entry frent;
2875+
nghttp3_frame fr;
28742876
uint8_t *buf = NULL;
28752877

28762878
assert(!conn->server);
@@ -2895,14 +2897,14 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
28952897
memcpy(buf, data, datalen);
28962898
}
28972899

2898-
frent.fr.priority_update = (nghttp3_frame_priority_update){
2900+
fr.priority_update = (nghttp3_frame_priority_update){
28992901
.type = NGHTTP3_FRAME_PRIORITY_UPDATE,
29002902
.pri_elem_id = stream_id,
29012903
.data = buf,
29022904
.datalen = datalen,
29032905
};
29042906

2905-
return nghttp3_stream_frq_add(conn->tx.ctrl, &frent);
2907+
return nghttp3_stream_frq_add(conn->tx.ctrl, &fr);
29062908
}
29072909

29082910
int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,

lib/nghttp3_frame.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ typedef struct nghttp3_frame_hd {
6060

6161
typedef struct nghttp3_frame_data {
6262
int64_t type;
63+
/* dr is set when sending DATA frame. It is not used on
64+
reception. */
65+
nghttp3_data_reader dr;
6366
} nghttp3_frame_data;
6467

6568
typedef struct nghttp3_frame_headers {
@@ -88,6 +91,9 @@ typedef struct nghttp3_frame_settings {
8891
int64_t type;
8992
size_t niv;
9093
nghttp3_settings_entry *iv;
94+
/* local_settings is set when sending SETTINGS frame. It is not
95+
used on reception. */
96+
nghttp3_settings *local_settings;
9197
} nghttp3_frame_settings;
9298

9399
typedef struct nghttp3_frame_goaway {

lib/nghttp3_stream.c

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
7373

7474
nghttp3_tnode_init(&stream->node, stream_id);
7575

76-
nghttp3_ringbuf_init(&stream->frq, 0, sizeof(nghttp3_frame_entry), mem);
76+
nghttp3_ringbuf_init(&stream->frq, 0, sizeof(nghttp3_frame), mem);
7777
nghttp3_ringbuf_init(&stream->chunks, 0, sizeof(nghttp3_buf), mem);
7878
nghttp3_ringbuf_init(&stream->outq, 0, sizeof(nghttp3_typed_buf), mem);
7979
nghttp3_ringbuf_init(&stream->inq, 0, sizeof(nghttp3_buf), mem);
@@ -136,17 +136,17 @@ static void delete_out_chunks(nghttp3_ringbuf *chunks,
136136
}
137137

138138
static void delete_frq(nghttp3_ringbuf *frq, const nghttp3_mem *mem) {
139-
nghttp3_frame_entry *frent;
139+
nghttp3_frame *fr;
140140
size_t i, len = nghttp3_ringbuf_len(frq);
141141

142142
for (i = 0; i < len; ++i) {
143-
frent = nghttp3_ringbuf_get(frq, i);
144-
switch (frent->fr.hd.type) {
143+
fr = nghttp3_ringbuf_get(frq, i);
144+
switch (fr->hd.type) {
145145
case NGHTTP3_FRAME_HEADERS:
146-
nghttp3_frame_headers_free(&frent->fr.headers, mem);
146+
nghttp3_frame_headers_free(&fr->headers, mem);
147147
break;
148148
case NGHTTP3_FRAME_PRIORITY_UPDATE:
149-
nghttp3_frame_priority_update_free(&frent->fr.priority_update, mem);
149+
nghttp3_frame_priority_update_free(&fr->priority_update, mem);
150150
break;
151151
default:
152152
break;
@@ -223,10 +223,9 @@ nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
223223
return (nghttp3_ssize)len;
224224
}
225225

226-
int nghttp3_stream_frq_add(nghttp3_stream *stream,
227-
const nghttp3_frame_entry *frent) {
226+
int nghttp3_stream_frq_add(nghttp3_stream *stream, const nghttp3_frame *fr) {
228227
nghttp3_ringbuf *frq = &stream->frq;
229-
nghttp3_frame_entry *dest;
228+
nghttp3_frame *dest;
230229
int rv;
231230

232231
if (nghttp3_ringbuf_full(frq)) {
@@ -239,37 +238,37 @@ int nghttp3_stream_frq_add(nghttp3_stream *stream,
239238
}
240239

241240
dest = nghttp3_ringbuf_push_back(frq);
242-
*dest = *frent;
241+
*dest = *fr;
243242

244243
return 0;
245244
}
246245

247246
int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
248247
nghttp3_ringbuf *frq = &stream->frq;
249-
nghttp3_frame_entry *frent;
248+
nghttp3_frame *fr;
250249
int data_eof;
251250
int rv;
252251

253252
for (; nghttp3_ringbuf_len(frq) &&
254253
stream->unsent_bytes < NGHTTP3_MIN_UNSENT_BYTES;) {
255-
frent = nghttp3_ringbuf_get(frq, 0);
254+
fr = nghttp3_ringbuf_get(frq, 0);
256255

257-
switch (frent->fr.hd.type) {
256+
switch (fr->hd.type) {
258257
case NGHTTP3_FRAME_SETTINGS:
259-
rv = nghttp3_stream_write_settings(stream, frent);
258+
rv = nghttp3_stream_write_settings(stream, &fr->settings);
260259
if (rv != 0) {
261260
return rv;
262261
}
263262
break;
264263
case NGHTTP3_FRAME_HEADERS:
265-
rv = nghttp3_stream_write_headers(stream, frent);
264+
rv = nghttp3_stream_write_headers(stream, &fr->headers);
266265
if (rv != 0) {
267266
return rv;
268267
}
269-
nghttp3_frame_headers_free(&frent->fr.headers, stream->mem);
268+
nghttp3_frame_headers_free(&fr->headers, stream->mem);
270269
break;
271270
case NGHTTP3_FRAME_DATA:
272-
rv = nghttp3_stream_write_data(stream, &data_eof, frent);
271+
rv = nghttp3_stream_write_data(stream, &data_eof, &fr->data);
273272
if (rv != 0) {
274273
return rv;
275274
}
@@ -281,21 +280,20 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) {
281280
}
282281
break;
283282
case NGHTTP3_FRAME_GOAWAY:
284-
rv = nghttp3_stream_write_goaway(stream, frent);
283+
rv = nghttp3_stream_write_goaway(stream, &fr->goaway);
285284
if (rv != 0) {
286285
return rv;
287286
}
288287
break;
289288
case NGHTTP3_FRAME_PRIORITY_UPDATE:
290-
rv = nghttp3_stream_write_priority_update(stream, frent);
289+
rv = nghttp3_stream_write_priority_update(stream, &fr->priority_update);
291290
if (rv != 0) {
292291
return rv;
293292
}
294-
nghttp3_frame_priority_update_free(&frent->fr.priority_update,
295-
stream->mem);
293+
nghttp3_frame_priority_update_free(&fr->priority_update, stream->mem);
296294
break;
297295
case NGHTTP3_FRAME_ORIGIN:
298-
rv = nghttp3_stream_write_origin(stream, frent);
296+
rv = nghttp3_stream_write_origin(stream, &fr->origin);
299297
if (rv != 0) {
300298
return rv;
301299
}
@@ -333,7 +331,7 @@ int nghttp3_stream_write_stream_type(nghttp3_stream *stream) {
333331
}
334332

335333
int nghttp3_stream_write_settings(nghttp3_stream *stream,
336-
nghttp3_frame_entry *frent) {
334+
const nghttp3_frame_settings *infr) {
337335
size_t len;
338336
int rv;
339337
nghttp3_buf *chunk;
@@ -344,7 +342,7 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
344342
.niv = 3,
345343
.iv = ents,
346344
};
347-
nghttp3_settings *local_settings = frent->aux.settings.local_settings;
345+
nghttp3_settings *local_settings = infr->local_settings;
348346
int64_t payloadlen;
349347

350348
ents[0] = (nghttp3_settings_entry){
@@ -396,8 +394,7 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream,
396394
}
397395

398396
int nghttp3_stream_write_goaway(nghttp3_stream *stream,
399-
nghttp3_frame_entry *frent) {
400-
nghttp3_frame_goaway *fr = &frent->fr.goaway;
397+
const nghttp3_frame_goaway *fr) {
401398
size_t len;
402399
int rv;
403400
nghttp3_buf *chunk;
@@ -421,9 +418,8 @@ int nghttp3_stream_write_goaway(nghttp3_stream *stream,
421418
return nghttp3_stream_outq_add(stream, &tbuf);
422419
}
423420

424-
int nghttp3_stream_write_priority_update(nghttp3_stream *stream,
425-
nghttp3_frame_entry *frent) {
426-
nghttp3_frame_priority_update *fr = &frent->fr.priority_update;
421+
int nghttp3_stream_write_priority_update(
422+
nghttp3_stream *stream, const nghttp3_frame_priority_update *fr) {
427423
size_t len;
428424
int rv;
429425
nghttp3_buf *chunk;
@@ -449,8 +445,7 @@ int nghttp3_stream_write_priority_update(nghttp3_stream *stream,
449445
}
450446

451447
int nghttp3_stream_write_origin(nghttp3_stream *stream,
452-
nghttp3_frame_entry *frent) {
453-
nghttp3_frame_origin *fr = &frent->fr.origin;
448+
const nghttp3_frame_origin *fr) {
454449
nghttp3_buf *chunk;
455450
nghttp3_buf buf;
456451
nghttp3_typed_buf tbuf;
@@ -488,8 +483,7 @@ int nghttp3_stream_write_origin(nghttp3_stream *stream,
488483
}
489484

490485
int nghttp3_stream_write_headers(nghttp3_stream *stream,
491-
nghttp3_frame_entry *frent) {
492-
nghttp3_frame_headers *fr = &frent->fr.headers;
486+
const nghttp3_frame_headers *fr) {
493487
nghttp3_conn *conn = stream->conn;
494488

495489
assert(conn);
@@ -610,13 +604,13 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream,
610604
}
611605

612606
int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
613-
nghttp3_frame_entry *frent) {
607+
const nghttp3_frame_data *fr) {
614608
int rv;
615609
size_t len;
616610
nghttp3_typed_buf tbuf;
617611
nghttp3_buf buf;
618612
nghttp3_buf *chunk;
619-
nghttp3_read_data_callback read_data = frent->aux.data.dr.read_data;
613+
nghttp3_read_data_callback read_data = fr->dr.read_data;
620614
nghttp3_conn *conn = stream->conn;
621615
int64_t datalen;
622616
uint32_t flags = 0;

0 commit comments

Comments
 (0)