| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,7 +73,7 @@ const kType = Symbol('type'); | |||
| 73 | 73 | const kDefaultSocketTimeout = 2 * 60 * 1000; | |
| 74 | 74 | const kRenegTest = /TLS session renegotiation disabled for this socket/; | |
| 75 | 75 | ||
| 76 | - const paddingBuffer = new Uint32Array(binding.paddingArrayBuffer); | ||
| 76 | + const { paddingBuffer } = binding; | ||
| 77 | 77 | ||
| 78 | 78 | const { | |
| 79 | 79 | NGHTTP2_CANCEL, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,16 +114,14 @@ const kNoPayloadMethods = new Set([ | |||
| 114 | 114 | // the native side with values that are filled in on demand, the js code then | |
| 115 | 115 | // reads those values out. The set of IDX constants that follow identify the | |
| 116 | 116 | // relevant data positions within these buffers. | |
| 117 | - const settingsBuffer = new Uint32Array(binding.settingsArrayBuffer); | ||
| 118 | - const optionsBuffer = new Uint32Array(binding.optionsArrayBuffer); | ||
| 117 | + const { settingsBuffer, optionsBuffer } = binding; | ||
| 119 | 118 | ||
| 120 | 119 | // Note that Float64Array is used here because there is no Int64Array available | |
| 121 | 120 | // and these deal with numbers that can be beyond the range of Uint32 and Int32. | |
| 122 | 121 | // The values set on the native side will always be integers. This is not a | |
| 123 | 122 | // unique example of this, this pattern can be found in use in other parts of | |
| 124 | 123 | // Node.js core as a performance optimization. | |
| 125 | - const sessionState = new Float64Array(binding.sessionStateArrayBuffer); | ||
| 126 | - const streamState = new Float64Array(binding.streamStateArrayBuffer); | ||
| 124 | + const { sessionState, streamState } = binding; | ||
| 127 | 125 | ||
| 128 | 126 | const IDX_SETTINGS_HEADER_TABLE_SIZE = 0; | |
| 129 | 127 | const IDX_SETTINGS_ENABLE_PUSH = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -329,6 +329,7 @@ inline Environment::~Environment() { | |||
| 329 | 329 | delete[] heap_statistics_buffer_; | |
| 330 | 330 | delete[] heap_space_statistics_buffer_; | |
| 331 | 331 | delete[] http_parser_buffer_; | |
| 332 | + free(http2_state_buffer_); | ||
| 332 | 333 | } | |
| 333 | 334 | ||
| 334 | 335 | inline v8::Isolate* Environment::isolate() const { | |
@@ -478,6 +479,15 @@ inline void Environment::set_http_parser_buffer(char* buffer) { | |||
| 478 | 479 | http_parser_buffer_ = buffer; | |
| 479 | 480 | } | |
| 480 | 481 | ||
| 482 | + inline http2::http2_state* Environment::http2_state_buffer() const { | ||
| 483 | + return http2_state_buffer_; | ||
| 484 | + } | ||
| 485 | + | ||
| 486 | + inline void Environment::set_http2_state_buffer(http2::http2_state* buffer) { | ||
| 487 | + CHECK_EQ(http2_state_buffer_, nullptr); // Should be set only once. | ||
| 488 | + http2_state_buffer_ = buffer; | ||
| 489 | + } | ||
| 490 | + | ||
| 481 | 491 | inline double* Environment::fs_stats_field_array() const { | |
| 482 | 492 | return fs_stats_field_array_; | |
| 483 | 493 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,10 @@ | |||
| 43 | 43 | ||
| 44 | 44 | namespace node { | |
| 45 | 45 | ||
| 46 | + namespace http2 { | ||
| 47 | + struct http2_state; | ||
| 48 | + } | ||
| 49 | + | ||
| 46 | 50 | // Pick an index that's hopefully out of the way when we're embedded inside | |
| 47 | 51 | // another application. Performance-wise or memory-wise it doesn't matter: | |
| 48 | 52 | // Context::SetAlignedPointerInEmbedderData() is backed by a FixedArray, | |
@@ -599,6 +603,9 @@ class Environment { | |||
| 599 | 603 | inline char* http_parser_buffer() const; | |
| 600 | 604 | inline void set_http_parser_buffer(char* buffer); | |
| 601 | 605 | ||
| 606 | + inline http2::http2_state* http2_state_buffer() const; | ||
| 607 | + inline void set_http2_state_buffer(http2::http2_state* buffer); | ||
| 608 | + | ||
| 602 | 609 | inline double* fs_stats_field_array() const; | |
| 603 | 610 | inline void set_fs_stats_field_array(double* fields); | |
| 604 | 611 | ||
@@ -705,6 +712,7 @@ class Environment { | |||
| 705 | 712 | double* heap_space_statistics_buffer_ = nullptr; | |
| 706 | 713 | ||
| 707 | 714 | char* http_parser_buffer_; | |
| 715 | + http2::http2_state* http2_state_buffer_ = nullptr; | ||
| 708 | 716 | ||
| 709 | 717 | double* fs_stats_field_array_; | |
| 710 | 718 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,10 +7,12 @@ namespace node { | |||
| 7 | 7 | using v8::ArrayBuffer; | |
| 8 | 8 | using v8::Boolean; | |
| 9 | 9 | using v8::Context; | |
| 10 | + using v8::Float64Array; | ||
| 10 | 11 | using v8::Function; | |
| 11 | 12 | using v8::Integer; | |
| 12 | 13 | using v8::String; | |
| 13 | 14 | using v8::Uint32; | |
| 15 | + using v8::Uint32Array; | ||
| 14 | 16 | using v8::Undefined; | |
| 15 | 17 | ||
| 16 | 18 | namespace http2 { | |
@@ -57,27 +59,18 @@ enum Http2OptionsIndex { | |||
| 57 | 59 | IDX_OPTIONS_FLAGS | |
| 58 | 60 | }; | |
| 59 | 61 | ||
| 60 | - static uint32_t http2_padding_buffer[3]; | ||
| 61 | - static uint32_t http2_options_buffer[IDX_OPTIONS_FLAGS + 1]; | ||
| 62 | - static uint32_t http2_settings_buffer[IDX_SETTINGS_COUNT + 1]; | ||
| 63 | - static double http2_session_state_buffer[IDX_SESSION_STATE_COUNT]; | ||
| 64 | - static double http2_stream_state_buffer[IDX_STREAM_STATE_COUNT]; | ||
| 65 | - | ||
| 66 | - static const size_t http2_options_buffer_byte_length = | ||
| 67 | - sizeof(http2_options_buffer) * (IDX_OPTIONS_FLAGS + 1); | ||
| 68 | - static const size_t http2_settings_buffer_byte_length = | ||
| 69 | - sizeof(http2_settings_buffer) * (IDX_SETTINGS_COUNT + 1); | ||
| 70 | - static const size_t http2_padding_buffer_byte_length = | ||
| 71 | - sizeof(http2_padding_buffer) * 3; | ||
| 72 | - static const size_t http2_stream_state_buffer_byte_length = | ||
| 73 | - sizeof(http2_stream_state_buffer) * IDX_STREAM_STATE_COUNT; | ||
| 74 | - static const size_t http2_session_state_buffer_byte_length = | ||
| 75 | - sizeof(http2_session_state_buffer) * IDX_SESSION_STATE_COUNT; | ||
| 62 | + struct http2_state { | ||
| 63 | + uint32_t padding_buffer[3]; | ||
| 64 | + uint32_t options_buffer[IDX_OPTIONS_FLAGS + 1]; | ||
| 65 | + uint32_t settings_buffer[IDX_SETTINGS_COUNT + 1]; | ||
| 66 | + double session_state_buffer[IDX_SESSION_STATE_COUNT]; | ||
| 67 | + double stream_state_buffer[IDX_STREAM_STATE_COUNT]; | ||
| 68 | + }; | ||
| 76 | 69 | ||
| 77 | 70 | Http2Options::Http2Options(Environment* env) { | |
| 78 | 71 | nghttp2_option_new(&options_); | |
| 79 | 72 | ||
| 80 | - uint32_t* buffer = http2_options_buffer; | ||
| 73 | + uint32_t* buffer = env->http2_state_buffer()->options_buffer; | ||
| 81 | 74 | uint32_t flags = buffer[IDX_OPTIONS_FLAGS]; | |
| 82 | 75 | ||
| 83 | 76 | if (flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE)) { | |
@@ -126,7 +119,7 @@ ssize_t Http2Session::OnCallbackPadding(size_t frameLen, | |||
| 126 | 119 | Context::Scope context_scope(context); | |
| 127 | 120 | ||
| 128 | 121 | if (object()->Has(context, env()->ongetpadding_string()).FromJust()) { | |
| 129 | - uint32_t* buffer = http2_padding_buffer; | ||
| 122 | + uint32_t* buffer = env()->http2_state_buffer()->padding_buffer; | ||
| 130 | 123 | buffer[0] = frameLen; | |
| 131 | 124 | buffer[1] = maxPayloadLen; | |
| 132 | 125 | MakeCallback(env()->ongetpadding_string(), 0, nullptr); | |
@@ -167,7 +160,7 @@ void PackSettings(const FunctionCallbackInfo<Value>& args) { | |||
| 167 | 160 | std::vector<nghttp2_settings_entry> entries; | |
| 168 | 161 | entries.reserve(6); | |
| 169 | 162 | ||
| 170 | - uint32_t* buffer = http2_settings_buffer; | ||
| 163 | + uint32_t* buffer = env->http2_state_buffer()->settings_buffer; | ||
| 171 | 164 | uint32_t flags = buffer[IDX_SETTINGS_COUNT]; | |
| 172 | 165 | ||
| 173 | 166 | if (flags & (1 << IDX_SETTINGS_HEADER_TABLE_SIZE)) { | |
@@ -226,7 +219,8 @@ void PackSettings(const FunctionCallbackInfo<Value>& args) { | |||
| 226 | 219 | // Used to fill in the spec defined initial values for each setting. | |
| 227 | 220 | void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) { | |
| 228 | 221 | DEBUG_HTTP2("Http2Session: refreshing default settings\n"); | |
| 229 | - uint32_t* buffer = http2_settings_buffer; | ||
| 222 | + Environment* env = Environment::GetCurrent(args); | ||
| 223 | + uint32_t* buffer = env->http2_state_buffer()->settings_buffer; | ||
| 230 | 224 | buffer[IDX_SETTINGS_HEADER_TABLE_SIZE] = | |
| 231 | 225 | DEFAULT_SETTINGS_HEADER_TABLE_SIZE; | |
| 232 | 226 | buffer[IDX_SETTINGS_ENABLE_PUSH] = | |
@@ -245,13 +239,14 @@ void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) { | |||
| 245 | 239 | template <get_setting fn> | |
| 246 | 240 | void RefreshSettings(const FunctionCallbackInfo<Value>& args) { | |
| 247 | 241 | DEBUG_HTTP2("Http2Session: refreshing settings for session\n"); | |
| 242 | + Environment* env = Environment::GetCurrent(args); | ||
| 248 | 243 | CHECK_EQ(args.Length(), 1); | |
| 249 | 244 | CHECK(args[0]->IsObject()); | |
| 250 | 245 | Http2Session* session; | |
| 251 | 246 | ASSIGN_OR_RETURN_UNWRAP(&session, args[0].As<Object>()); | |
| 252 | 247 | nghttp2_session* s = session->session(); | |
| 253 | 248 | ||
| 254 | - uint32_t* buffer = http2_settings_buffer; | ||
| 249 | + uint32_t* buffer = env->http2_state_buffer()->settings_buffer; | ||
| 255 | 250 | buffer[IDX_SETTINGS_HEADER_TABLE_SIZE] = | |
| 256 | 251 | fn(s, NGHTTP2_SETTINGS_HEADER_TABLE_SIZE); | |
| 257 | 252 | buffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS] = | |
@@ -269,9 +264,10 @@ void RefreshSettings(const FunctionCallbackInfo<Value>& args) { | |||
| 269 | 264 | // Used to fill in the spec defined initial values for each setting. | |
| 270 | 265 | void RefreshSessionState(const FunctionCallbackInfo<Value>& args) { | |
| 271 | 266 | DEBUG_HTTP2("Http2Session: refreshing session state\n"); | |
| 267 | + Environment* env = Environment::GetCurrent(args); | ||
| 272 | 268 | CHECK_EQ(args.Length(), 1); | |
| 273 | 269 | CHECK(args[0]->IsObject()); | |
| 274 | - double* buffer = http2_session_state_buffer; | ||
| 270 | + double* buffer = env->http2_state_buffer()->session_state_buffer; | ||
| 275 | 271 | Http2Session* session; | |
| 276 | 272 | ASSIGN_OR_RETURN_UNWRAP(&session, args[0].As<Object>()); | |
| 277 | 273 | nghttp2_session* s = session->session(); | |
@@ -308,7 +304,7 @@ void RefreshStreamState(const FunctionCallbackInfo<Value>& args) { | |||
| 308 | 304 | nghttp2_session* s = session->session(); | |
| 309 | 305 | Nghttp2Stream* stream; | |
| 310 | 306 | ||
| 311 | - double* buffer = http2_stream_state_buffer; | ||
| 307 | + double* buffer = env->http2_state_buffer()->stream_state_buffer; | ||
| 312 | 308 | ||
| 313 | 309 | if ((stream = session->FindStream(id)) == nullptr) { | |
| 314 | 310 | buffer[IDX_STREAM_STATE] = NGHTTP2_STREAM_STATE_IDLE; | |
@@ -418,8 +414,9 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) { | |||
| 418 | 414 | void Http2Session::SubmitSettings(const FunctionCallbackInfo<Value>& args) { | |
| 419 | 415 | Http2Session* session; | |
| 420 | 416 | ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder()); | |
| 417 | + Environment* env = session->env(); | ||
| 421 | 418 | ||
| 422 | - uint32_t* buffer = http2_settings_buffer; | ||
| 419 | + uint32_t* buffer = env->http2_state_buffer()->settings_buffer; | ||
| 423 | 420 | uint32_t flags = buffer[IDX_SETTINGS_COUNT]; | |
| 424 | 421 | ||
| 425 | 422 | std::vector<nghttp2_settings_entry> entries; | |
@@ -1148,43 +1145,27 @@ void Initialize(Local<Object> target, | |||
| 1148 | 1145 | Isolate* isolate = env->isolate(); | |
| 1149 | 1146 | HandleScope scope(isolate); | |
| 1150 | 1147 | ||
| 1151 | - // Initialize the buffer used for padding callbacks | ||
| 1152 | - target->Set(context, | ||
| 1153 | - FIXED_ONE_BYTE_STRING(isolate, "paddingArrayBuffer"), | ||
| 1154 | - ArrayBuffer::New(isolate, | ||
| 1155 | - &http2_padding_buffer, | ||
| 1156 | - http2_padding_buffer_byte_length)) | ||
| 1157 | - .FromJust(); | ||
| 1148 | + http2_state* state = Calloc<http2_state>(1); | ||
| 1149 | + env->set_http2_state_buffer(state); | ||
| 1150 | + auto state_ab = ArrayBuffer::New(isolate, state, sizeof(*state)); | ||
| 1158 | 1151 | ||
| 1159 | - // Initialize the buffer used to store the session state | ||
| 1160 | - target->Set(context, | ||
| 1161 | - FIXED_ONE_BYTE_STRING(isolate, "sessionStateArrayBuffer"), | ||
| 1162 | - ArrayBuffer::New(isolate, | ||
| 1163 | - &http2_session_state_buffer, | ||
| 1164 | - http2_session_state_buffer_byte_length)) | ||
| 1165 | - .FromJust(); | ||
| 1152 | + #define SET_STATE_TYPEDARRAY(name, type, field) \ | ||
| 1153 | + target->Set(context, \ | ||
| 1154 | + FIXED_ONE_BYTE_STRING(isolate, (name)), \ | ||
| 1155 | + type::New(state_ab, \ | ||
| 1156 | + offsetof(http2_state, field), \ | ||
| 1157 | + arraysize(state->field))) \ | ||
| 1158 | + .FromJust() | ||
| 1166 | 1159 | ||
| 1160 | + // Initialize the buffer used for padding callbacks | ||
| 1161 | + SET_STATE_TYPEDARRAY("paddingBuffer", Uint32Array, padding_buffer); | ||
| 1162 | + // Initialize the buffer used to store the session state | ||
| 1163 | + SET_STATE_TYPEDARRAY("sessionState", Float64Array, session_state_buffer); | ||
| 1167 | 1164 | // Initialize the buffer used to store the stream state | |
| 1168 | - target->Set(context, | ||
| 1169 | - FIXED_ONE_BYTE_STRING(isolate, "streamStateArrayBuffer"), | ||
| 1170 | - ArrayBuffer::New(isolate, | ||
| 1171 | - &http2_stream_state_buffer, | ||
| 1172 | - http2_stream_state_buffer_byte_length)) | ||
| 1173 | - .FromJust(); | ||
| 1174 | - | ||
| 1175 | - target->Set(context, | ||
| 1176 | - FIXED_ONE_BYTE_STRING(isolate, "settingsArrayBuffer"), | ||
| 1177 | - ArrayBuffer::New(isolate, | ||
| 1178 | - &http2_settings_buffer, | ||
| 1179 | - http2_settings_buffer_byte_length)) | ||
| 1180 | - .FromJust(); | ||
| 1181 | - | ||
| 1182 | - target->Set(context, | ||
| 1183 | - FIXED_ONE_BYTE_STRING(isolate, "optionsArrayBuffer"), | ||
| 1184 | - ArrayBuffer::New(isolate, | ||
| 1185 | - &http2_options_buffer, | ||
| 1186 | - http2_options_buffer_byte_length)) | ||
| 1187 | - .FromJust(); | ||
| 1165 | + SET_STATE_TYPEDARRAY("streamState", Float64Array, stream_state_buffer); | ||
| 1166 | + SET_STATE_TYPEDARRAY("settingsBuffer", Uint32Array, settings_buffer); | ||
| 1167 | + SET_STATE_TYPEDARRAY("optionsBuffer", Uint32Array, options_buffer); | ||
| 1168 | + #undef SET_STATE_TYPEDARRAY | ||
| 1188 | 1169 | ||
| 1189 | 1170 | // Method to fetch the nghttp2 string description of an nghttp2 error code | |
| 1190 | 1171 | env->SetMethod(target, "nghttp2ErrorString", HttpErrorString); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments