From 5ea25d2ebeb61ea209171f5f5cb72d4072a2c969 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 10 Aug 2017 17:56:23 +0200 Subject: [PATCH] http2: name padding buffer fields PR-URL: https://github.com/nodejs/node/pull/14744 Reviewed-By: James M Snell --- lib/internal/http2/core.js | 20 +++++++++++++------- src/node_http2.cc | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 972cdc97333739..6a701179cee0da 100755 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -73,7 +73,12 @@ const kType = Symbol('type'); const kDefaultSocketTimeout = 2 * 60 * 1000; const kRenegTest = /TLS session renegotiation disabled for this socket/; -const { paddingBuffer } = binding; +const { + paddingBuffer, + PADDING_BUF_FRAME_LENGTH, + PADDING_BUF_MAX_PAYLOAD_LENGTH, + PADDING_BUF_RETURN_VALUE +} = binding; const { NGHTTP2_CANCEL, @@ -393,12 +398,13 @@ function onSelectPadding(fn) { 'bug in Node.js'); return function getPadding() { debug('fetching padding for frame'); - const frameLen = paddingBuffer[0]; - const maxFramePayloadLen = paddingBuffer[1]; - paddingBuffer[2] = Math.min(maxFramePayloadLen, - Math.max(frameLen, - fn(frameLen, - maxFramePayloadLen) | 0)); + const frameLen = paddingBuffer[PADDING_BUF_FRAME_LENGTH]; + const maxFramePayloadLen = paddingBuffer[PADDING_BUF_MAX_PAYLOAD_LENGTH]; + paddingBuffer[PADDING_BUF_RETURN_VALUE] = + Math.min(maxFramePayloadLen, + Math.max(frameLen, + fn(frameLen, + maxFramePayloadLen) | 0)); }; } diff --git a/src/node_http2.cc b/src/node_http2.cc index d5dbdb80a0431d..ee6e604a851984 100755 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -59,8 +59,15 @@ enum Http2OptionsIndex { IDX_OPTIONS_FLAGS }; +enum Http2PaddingBufferFields { + PADDING_BUF_FRAME_LENGTH, + PADDING_BUF_MAX_PAYLOAD_LENGTH, + PADDING_BUF_RETURN_VALUE, + PADDING_BUF_FIELD_COUNT +}; + struct http2_state { - uint32_t padding_buffer[3]; + uint32_t padding_buffer[PADDING_BUF_FIELD_COUNT]; uint32_t options_buffer[IDX_OPTIONS_FLAGS + 1]; uint32_t settings_buffer[IDX_SETTINGS_COUNT + 1]; double session_state_buffer[IDX_SESSION_STATE_COUNT]; @@ -120,10 +127,10 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen, if (object()->Has(context, env()->ongetpadding_string()).FromJust()) { uint32_t* buffer = env()->http2_state_buffer()->padding_buffer; - buffer[0] = frameLen; - buffer[1] = maxPayloadLen; + buffer[PADDING_BUF_FRAME_LENGTH] = frameLen; + buffer[PADDING_BUF_MAX_PAYLOAD_LENGTH] = maxPayloadLen; MakeCallback(env()->ongetpadding_string(), 0, nullptr); - uint32_t retval = buffer[2]; + uint32_t retval = buffer[PADDING_BUF_RETURN_VALUE]; retval = retval <= maxPayloadLen ? retval : maxPayloadLen; retval = retval >= frameLen ? retval : frameLen; CHECK_GE(retval, frameLen); @@ -1167,6 +1174,10 @@ void Initialize(Local target, SET_STATE_TYPEDARRAY("optionsBuffer", Uint32Array, options_buffer); #undef SET_STATE_TYPEDARRAY + NODE_DEFINE_CONSTANT(target, PADDING_BUF_FRAME_LENGTH); + NODE_DEFINE_CONSTANT(target, PADDING_BUF_MAX_PAYLOAD_LENGTH); + NODE_DEFINE_CONSTANT(target, PADDING_BUF_RETURN_VALUE); + // Method to fetch the nghttp2 string description of an nghttp2 error code env->SetMethod(target, "nghttp2ErrorString", HttpErrorString);