From 1fc7651b00f2a581951da8ea0c042ef3098edcde Mon Sep 17 00:00:00 2001 From: Yann Stephan Date: Thu, 28 Mar 2019 19:37:34 +0100 Subject: [PATCH 1/2] subsystem: http2 window size connection control Allow to control the connection window size by setting local window size (local endpoints's window size) to the given window_size. To increase window size, this function may submit WINDOW_UPDATE frame to transmission queue. Pay attention, this function takes the absolute value of window size to set, rather than the delta, the delta is computed by the update operation. --- doc/api/http2.md | 28 ++++++++++++++++++++++++++++ lib/internal/http2/core.js | 18 ++++++++++++++++++ src/node_http2.cc | 23 +++++++++++++++++++++++ src/node_http2.h | 1 + 4 files changed, 70 insertions(+) diff --git a/doc/api/http2.md b/doc/api/http2.md index 1416c976362afe..db1548300ec911 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -524,6 +524,33 @@ Used to set a callback function that is called when there is no activity on the `Http2Session` after `msecs` milliseconds. The given `callback` is registered as a listener on the `'timeout'` event. +#### http2session.setConnectionWindowSize(windowSize) + + +* `windowSize` {number} +* Returns: 0 +In case of allocation error, a new `ERR_OUT_OF_RANGE` +error will be thrown. + +Used to set the local window size (local endpoints's window size). +The window_size is an absolute value of window size to set, rather +than the delta. + +```js +clientSession.on('connect', (session) => sendSettings(session, (s) => cb(s))); + +function sendSettings(session, cb) { + session.setConnectionWindowSize(1024*1024); + + const settings = http2.getDefaultSettings(); + settings.initialWindowSize = WINDOW_SIZE; + settings.maxFrameSize = FRAME_SIZE; +} + +``` + #### http2session.socket * `windowSize` {number} -* Returns: 0 +* Returns: 0 if it succeeds, or one of a negative codes In case of allocation error, a new `ERR_OUT_OF_RANGE` error will be thrown. diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index bdd43568676526..552cf8fede8fe4 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1048,7 +1048,8 @@ class Http2Session extends EventEmitter { const ret = this[kHandle].setConnectionWindowSize(windowSize); if (typeof ret === 'number' && ret === NGHTTP2_ERR_NOMEM) { - throw new ERR_OUT_OF_RANGE('windowSize', `> 0 and <= 2^31-1 bytes`, windowSize) + throw new ERR_OUT_OF_RANGE('windowSize', `> 0 and <= 2^31-1 bytes`, + windowSize); } return ret; diff --git a/src/node_http2.cc b/src/node_http2.cc index 99318f421bd00c..c855994f653a62 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2368,7 +2368,7 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo& args) { // Set local window size (local endpoints's window size) to the given // window_size for the stream denoted by 0. -// If successful, returns 0. +// This function returns 0 if it succeeds, or one of a negative codes void Http2Session::SetConnectionWindowSize( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args);