Skip to content

Commit 86ee05d

Browse files
jasnellMylesBorins
authored andcommitted
http2: simplify TypeName
PR-URL: #15693 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 1582260 commit 86ee05d

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

src/node_http2_core-inl.h

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ inline int Nghttp2Session::OnNghttpError(nghttp2_session* session,
4040
void* user_data) {
4141
Nghttp2Session* handle = static_cast<Nghttp2Session*>(user_data);
4242
DEBUG_HTTP2("Nghttp2Session %s: Error '%.*s'\n",
43-
handle->TypeName(handle->type()), len, message);
43+
handle->TypeName(), len, message);
4444
return 0;
4545
}
4646
#endif
@@ -58,7 +58,7 @@ inline int Nghttp2Session::OnBeginHeadersCallback(nghttp2_session* session,
5858
frame->push_promise.promised_stream_id :
5959
frame->hd.stream_id;
6060
DEBUG_HTTP2("Nghttp2Session %s: beginning headers for stream %d\n",
61-
handle->TypeName(handle->type()), id);
61+
handle->TypeName(), id);
6262

6363
Nghttp2Stream* stream = handle->FindStream(id);
6464
if (stream == nullptr) {
@@ -103,7 +103,7 @@ inline int Nghttp2Session::OnFrameReceive(nghttp2_session* session,
103103
void* user_data) {
104104
Nghttp2Session* handle = static_cast<Nghttp2Session*>(user_data);
105105
DEBUG_HTTP2("Nghttp2Session %s: complete frame received: type: %d\n",
106-
handle->TypeName(handle->type()), frame->hd.type);
106+
handle->TypeName(), frame->hd.type);
107107
bool ack;
108108
switch (frame->hd.type) {
109109
case NGHTTP2_DATA:
@@ -135,7 +135,7 @@ inline int Nghttp2Session::OnFrameNotSent(nghttp2_session *session,
135135
void *user_data) {
136136
Nghttp2Session *handle = static_cast<Nghttp2Session *>(user_data);
137137
DEBUG_HTTP2("Nghttp2Session %s: frame type %d was not sent, code: %d\n",
138-
handle->TypeName(handle->type()), frame->hd.type, error_code);
138+
handle->TypeName(), frame->hd.type, error_code);
139139
// Do not report if the frame was not sent due to the session closing
140140
if (error_code != NGHTTP2_ERR_SESSION_CLOSING &&
141141
error_code != NGHTTP2_ERR_STREAM_CLOSED &&
@@ -162,7 +162,7 @@ inline int Nghttp2Session::OnStreamClose(nghttp2_session *session,
162162
void *user_data) {
163163
Nghttp2Session *handle = static_cast<Nghttp2Session *>(user_data);
164164
DEBUG_HTTP2("Nghttp2Session %s: stream %d closed, code: %d\n",
165-
handle->TypeName(handle->type()), id, code);
165+
handle->TypeName(), id, code);
166166
Nghttp2Stream *stream = handle->FindStream(id);
167167
// Intentionally ignore the callback if the stream does not exist
168168
if (stream != nullptr)
@@ -182,7 +182,7 @@ inline ssize_t Nghttp2Session::OnStreamReadFD(nghttp2_session *session,
182182
void *user_data) {
183183
Nghttp2Session *handle = static_cast<Nghttp2Session *>(user_data);
184184
DEBUG_HTTP2("Nghttp2Session %s: reading outbound file data for stream %d\n",
185-
handle->TypeName(handle->type()), id);
185+
handle->TypeName(), id);
186186
Nghttp2Stream *stream = handle->FindStream(id);
187187

188188
int fd = source->fd;
@@ -218,7 +218,7 @@ inline ssize_t Nghttp2Session::OnStreamReadFD(nghttp2_session *session,
218218
// if numchars < length, assume that we are done.
219219
if (static_cast<size_t>(numchars) < length || length <= 0) {
220220
DEBUG_HTTP2("Nghttp2Session %s: no more data for stream %d\n",
221-
handle->TypeName(handle->type()), id);
221+
handle->TypeName(), id);
222222
*flags |= NGHTTP2_DATA_FLAG_EOF;
223223
GetTrailers(session, handle, stream, flags);
224224
}
@@ -238,7 +238,7 @@ inline ssize_t Nghttp2Session::OnStreamRead(nghttp2_session *session,
238238
void *user_data) {
239239
Nghttp2Session *handle = static_cast<Nghttp2Session *>(user_data);
240240
DEBUG_HTTP2("Nghttp2Session %s: reading outbound data for stream %d\n",
241-
handle->TypeName(handle->type()), id);
241+
handle->TypeName(), id);
242242
Nghttp2Stream *stream = handle->FindStream(id);
243243
size_t remaining = length;
244244
size_t offset = 0;
@@ -248,7 +248,7 @@ inline ssize_t Nghttp2Session::OnStreamRead(nghttp2_session *session,
248248
// calls this callback.
249249
while (stream->queue_head_ != nullptr) {
250250
DEBUG_HTTP2("Nghttp2Session %s: processing outbound data chunk\n",
251-
handle->TypeName(handle->type()));
251+
handle->TypeName());
252252
nghttp2_stream_write_queue *head = stream->queue_head_;
253253
while (stream->queue_head_index_ < head->nbufs) {
254254
if (remaining == 0)
@@ -289,12 +289,12 @@ inline ssize_t Nghttp2Session::OnStreamRead(nghttp2_session *session,
289289
int writable = stream->queue_head_ != nullptr || stream->IsWritable();
290290
if (offset == 0 && writable && stream->queue_head_ == nullptr) {
291291
DEBUG_HTTP2("Nghttp2Session %s: deferring stream %d\n",
292-
handle->TypeName(handle->type()), id);
292+
handle->TypeName(), id);
293293
return NGHTTP2_ERR_DEFERRED;
294294
}
295295
if (!writable) {
296296
DEBUG_HTTP2("Nghttp2Session %s: no more data for stream %d\n",
297-
handle->TypeName(handle->type()), id);
297+
handle->TypeName(), id);
298298
*flags |= NGHTTP2_DATA_FLAG_EOF;
299299

300300
GetTrailers(session, handle, stream, flags);
@@ -313,7 +313,7 @@ inline ssize_t Nghttp2Session::OnSelectPadding(nghttp2_session *session,
313313
CHECK(handle->HasGetPaddingCallback());
314314
ssize_t padding = handle->GetPadding(frame->hd.length, maxPayloadLen);
315315
DEBUG_HTTP2("Nghttp2Session %s: using padding, size: %d\n",
316-
handle->TypeName(handle->type()), padding);
316+
handle->TypeName(), padding);
317317
return padding;
318318
}
319319

@@ -326,7 +326,7 @@ inline int Nghttp2Session::OnDataChunkReceived(nghttp2_session *session,
326326
void *user_data) {
327327
Nghttp2Session *handle = static_cast<Nghttp2Session *>(user_data);
328328
DEBUG_HTTP2("Nghttp2Session %s: buffering data chunk for stream %d, size: "
329-
"%d, flags: %d\n", handle->TypeName(handle->type()),
329+
"%d, flags: %d\n", handle->TypeName(),
330330
id, len, flags);
331331
Nghttp2Stream *stream = handle->FindStream(id);
332332
nghttp2_data_chunk_t *chunk = data_chunk_free_list.pop();
@@ -361,7 +361,7 @@ inline void Nghttp2Session::SubmitTrailers::Submit(nghttp2_nv *trailers,
361361
if (length == 0)
362362
return;
363363
DEBUG_HTTP2("Nghttp2Session %s: sending trailers for stream %d, "
364-
"count: %d\n", handle_->TypeName(handle_->type()),
364+
"count: %d\n", handle_->TypeName(),
365365
stream_->id(), length);
366366
*flags_ |= NGHTTP2_DATA_FLAG_NO_END_STREAM;
367367
nghttp2_submit_trailer(handle_->session_,
@@ -373,7 +373,7 @@ inline void Nghttp2Session::SubmitTrailers::Submit(nghttp2_nv *trailers,
373373
// See: https://nghttp2.org/documentation/nghttp2_submit_shutdown_notice.html
374374
inline void Nghttp2Session::SubmitShutdownNotice() {
375375
DEBUG_HTTP2("Nghttp2Session %s: submitting shutdown notice\n",
376-
TypeName(type()));
376+
TypeName());
377377
nghttp2_submit_shutdown_notice(session_);
378378
}
379379

@@ -383,7 +383,7 @@ inline void Nghttp2Session::SubmitShutdownNotice() {
383383
inline int Nghttp2Session::SubmitSettings(const nghttp2_settings_entry iv[],
384384
size_t niv) {
385385
DEBUG_HTTP2("Nghttp2Session %s: submitting settings, count: %d\n",
386-
TypeName(type()), niv);
386+
TypeName(), niv);
387387
return nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, iv, niv);
388388
}
389389

@@ -392,11 +392,10 @@ inline Nghttp2Stream* Nghttp2Session::FindStream(int32_t id) {
392392
auto s = streams_.find(id);
393393
if (s != streams_.end()) {
394394
DEBUG_HTTP2("Nghttp2Session %s: stream %d found\n",
395-
TypeName(type()), id);
395+
TypeName(), id);
396396
return s->second;
397397
} else {
398-
DEBUG_HTTP2("Nghttp2Session %s: stream %d not found\n",
399-
TypeName(type()), id);
398+
DEBUG_HTTP2("Nghttp2Session %s: stream %d not found\n", TypeName(), id);
400399
return nullptr;
401400
}
402401
}
@@ -421,7 +420,7 @@ inline void Nghttp2Stream::FlushDataChunks(bool done) {
421420
inline void Nghttp2Session::HandleDataFrame(const nghttp2_frame* frame) {
422421
int32_t id = frame->hd.stream_id;
423422
DEBUG_HTTP2("Nghttp2Session %s: handling data frame for stream %d\n",
424-
TypeName(type()), id);
423+
TypeName(), id);
425424
Nghttp2Stream* stream = this->FindStream(id);
426425
// If the stream does not exist, something really bad happened
427426
CHECK_NE(stream, nullptr);
@@ -437,7 +436,7 @@ inline void Nghttp2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
437436
int32_t id = (frame->hd.type == NGHTTP2_PUSH_PROMISE) ?
438437
frame->push_promise.promised_stream_id : frame->hd.stream_id;
439438
DEBUG_HTTP2("Nghttp2Session %s: handling headers frame for stream %d\n",
440-
TypeName(type()), id);
439+
TypeName(), id);
441440
Nghttp2Stream* stream = FindStream(id);
442441
// If the stream does not exist, something really bad happened
443442
CHECK_NE(stream, nullptr);
@@ -453,7 +452,7 @@ inline void Nghttp2Session::HandlePriorityFrame(const nghttp2_frame* frame) {
453452
nghttp2_priority priority_frame = frame->priority;
454453
int32_t id = frame->hd.stream_id;
455454
DEBUG_HTTP2("Nghttp2Session %s: handling priority frame for stream %d\n",
456-
TypeName(type()), id);
455+
TypeName(), id);
457456
// Ignore the priority frame if stream ID is <= 0
458457
// This actually should never happen because nghttp2 should treat this as
459458
// an error condition that terminates the session.
@@ -466,7 +465,7 @@ inline void Nghttp2Session::HandlePriorityFrame(const nghttp2_frame* frame) {
466465
// Notifies the JS layer that a GOAWAY frame has been received
467466
inline void Nghttp2Session::HandleGoawayFrame(const nghttp2_frame* frame) {
468467
nghttp2_goaway goaway_frame = frame->goaway;
469-
DEBUG_HTTP2("Nghttp2Session %s: handling goaway frame\n", TypeName(type()));
468+
DEBUG_HTTP2("Nghttp2Session %s: handling goaway frame\n", TypeName());
470469

471470
OnGoAway(goaway_frame.last_stream_id,
472471
goaway_frame.error_code,
@@ -476,7 +475,7 @@ inline void Nghttp2Session::HandleGoawayFrame(const nghttp2_frame* frame) {
476475

477476
// Prompts nghttp2 to flush the queue of pending data frames
478477
inline void Nghttp2Session::SendPendingData() {
479-
DEBUG_HTTP2("Nghttp2Session %s: Sending pending data\n", TypeName(type()));
478+
DEBUG_HTTP2("Nghttp2Session %s: Sending pending data\n", TypeName());
480479
// Do not attempt to send data on the socket if the destroying flag has
481480
// been set. That means everything is shutting down and the socket
482481
// will not be usable.
@@ -510,10 +509,9 @@ inline int Nghttp2Session::Init(uv_loop_t* loop,
510509
const nghttp2_session_type type,
511510
nghttp2_option* options,
512511
nghttp2_mem* mem) {
513-
DEBUG_HTTP2("Nghttp2Session %s: initializing session\n",
514-
TypeName(type));
515512
loop_ = loop;
516513
session_type_ = type;
514+
DEBUG_HTTP2("Nghttp2Session %s: initializing session\n", TypeName());
517515
destroying_ = false;
518516
int ret = 0;
519517

@@ -565,7 +563,7 @@ inline void Nghttp2Session::MarkDestroying() {
565563

566564
inline int Nghttp2Session::Free() {
567565
CHECK(session_ != nullptr);
568-
DEBUG_HTTP2("Nghttp2Session %s: freeing session\n", TypeName(type()));
566+
DEBUG_HTTP2("Nghttp2Session %s: freeing session\n", TypeName());
569567
// Stop the loop
570568
uv_prepare_stop(&prep_);
571569
auto PrepClose = [](uv_handle_t* handle) {
@@ -579,7 +577,7 @@ inline int Nghttp2Session::Free() {
579577
nghttp2_session_del(session_);
580578
session_ = nullptr;
581579
loop_ = nullptr;
582-
DEBUG_HTTP2("Nghttp2Session %s: session freed\n", TypeName(type()));
580+
DEBUG_HTTP2("Nghttp2Session %s: session freed\n", TypeName());
583581
return 1;
584582
}
585583

src/node_http2_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class Nghttp2Session {
105105
return destroying_;
106106
}
107107

108-
inline const char* TypeName(nghttp2_session_type type) {
109-
switch (type) {
108+
inline const char* TypeName() {
109+
switch (session_type_) {
110110
case NGHTTP2_SESSION_SERVER: return "server";
111111
case NGHTTP2_SESSION_CLIENT: return "client";
112112
default:

0 commit comments

Comments
 (0)