Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: general code cleanups #19400

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
http2: clean up Http2Settings
Use of a MaybeStackBuffer was just silly. Fix a long standing todo
Reduce code duplication a bit.
  • Loading branch information
jasnell committed Mar 16, 2018
commit 1382a182b7d5c0205c0f3c09f7fe8f2e8b9a2638
62 changes: 15 additions & 47 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,60 +190,28 @@ Http2Options::Http2Options(Environment* env) {
}

void Http2Session::Http2Settings::Init() {
entries_.AllocateSufficientStorage(IDX_SETTINGS_COUNT);
AliasedBuffer<uint32_t, v8::Uint32Array>& buffer =
env()->http2_state()->settings_buffer;
uint32_t flags = buffer[IDX_SETTINGS_COUNT];

size_t n = 0;

if (flags & (1 << IDX_SETTINGS_HEADER_TABLE_SIZE)) {
uint32_t val = buffer[IDX_SETTINGS_HEADER_TABLE_SIZE];
DEBUG_HTTP2SESSION2(session_, "setting header table size: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
entries_[n].value = val;
n++;
#define GRABSETTING(N, trace) \
if (flags & (1 << IDX_SETTINGS_##N)) { \
uint32_t val = buffer[IDX_SETTINGS_##N]; \
DEBUG_HTTP2SESSION2(session_, "setting " trace ": %d\n", val); \
entries_[n++] = \
nghttp2_settings_entry {NGHTTP2_SETTINGS_##N, val}; \
}

if (flags & (1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS)) {
uint32_t val = buffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS];
DEBUG_HTTP2SESSION2(session_, "setting max concurrent streams: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
entries_[n].value = val;
n++;
}

if (flags & (1 << IDX_SETTINGS_MAX_FRAME_SIZE)) {
uint32_t val = buffer[IDX_SETTINGS_MAX_FRAME_SIZE];
DEBUG_HTTP2SESSION2(session_, "setting max frame size: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
entries_[n].value = val;
n++;
}

if (flags & (1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE)) {
uint32_t val = buffer[IDX_SETTINGS_INITIAL_WINDOW_SIZE];
DEBUG_HTTP2SESSION2(session_, "setting initial window size: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
entries_[n].value = val;
n++;
}

if (flags & (1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE)) {
uint32_t val = buffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE];
DEBUG_HTTP2SESSION2(session_, "setting max header list size: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE;
entries_[n].value = val;
n++;
}
GRABSETTING(HEADER_TABLE_SIZE, "header table size");
GRABSETTING(MAX_CONCURRENT_STREAMS, "max concurrent streams");
GRABSETTING(MAX_FRAME_SIZE, "max frame size");
GRABSETTING(INITIAL_WINDOW_SIZE, "initial window size");
GRABSETTING(MAX_HEADER_LIST_SIZE, "max header list size");
GRABSETTING(ENABLE_PUSH, "enable push");

if (flags & (1 << IDX_SETTINGS_ENABLE_PUSH)) {
uint32_t val = buffer[IDX_SETTINGS_ENABLE_PUSH];
DEBUG_HTTP2SESSION2(session_, "setting enable push: %d\n", val);
entries_[n].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH;
entries_[n].value = val;
n++;
}
#undef GRABSETTING

count_ = n;
}
Expand Down Expand Up @@ -289,7 +257,7 @@ Local<Value> Http2Session::Http2Settings::Pack() {
ssize_t ret =
nghttp2_pack_settings_payload(
reinterpret_cast<uint8_t*>(Buffer::Data(buf)), len,
*entries_, count_);
&entries_[0], count_);
if (ret >= 0)
return buf;
else
Expand Down Expand Up @@ -344,7 +312,7 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
void Http2Session::Http2Settings::Send() {
Http2Scope h2scope(session_);
CHECK_EQ(nghttp2_submit_settings(**session_, NGHTTP2_FLAG_NONE,
*entries_, length()), 0);
&entries_[0], count_), 0);
}

void Http2Session::Http2Settings::Done(bool ack) {
Expand Down
8 changes: 1 addition & 7 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,6 @@ class Http2Session::Http2Settings : public AsyncWrap {
void Send();
void Done(bool ack);

size_t length() const { return count_; }

nghttp2_settings_entry* operator*() {
return *entries_;
}

// Returns a Buffer instance with the serialized SETTINGS payload
Local<Value> Pack();

Expand All @@ -1207,7 +1201,7 @@ class Http2Session::Http2Settings : public AsyncWrap {
Http2Session* session_;
uint64_t startTime_;
size_t count_ = 0;
MaybeStackBuffer<nghttp2_settings_entry, IDX_SETTINGS_COUNT> entries_;
nghttp2_settings_entry entries_[IDX_SETTINGS_COUNT];
};

class ExternalHeader :
Expand Down