MCPcopy Index your code
hub / github.com/nodejs/node / setupHandle

Function setupHandle

lib/internal/http2/core.js:1095–1165  ·  view source on GitHub ↗
(socket, type, options)

Source from the content-addressed store, hash-verified

1093// established. Note: the binding.Http2Session will take over ownership
1094// of the socket. No other code should read from or write to the socket.
1095function setupHandle(socket, type, options) {
1096 // If the session has been destroyed, go ahead and emit 'connect',
1097 // but do nothing else. The various on('connect') handlers set by
1098 // core will check for session.destroyed before progressing, this
1099 // ensures that those at least get cleared out.
1100 if (this.destroyed) {
1101 process.nextTick(emit, this, 'connect', this, socket);
1102 return;
1103 }
1104
1105 assert(socket._handle !== undefined,
1106 'Internal HTTP/2 Failure. The socket is not connected. Please ' +
1107 'report this as a bug in Node.js');
1108
1109 debugSession(type, 'setting up session handle');
1110 this[kState].flags |= SESSION_FLAGS_READY;
1111
1112 updateOptionsBuffer(options);
1113 if (options.remoteCustomSettings) {
1114 remoteCustomSettingsToBuffer(options.remoteCustomSettings);
1115 }
1116 const handle = new binding.Http2Session(type);
1117 handle[kOwner] = this;
1118
1119 handle.consume(socket._handle);
1120 handle.ongracefulclosecomplete = this[kMaybeDestroy].bind(this, null);
1121
1122 this[kHandle] = handle;
1123 if (this[kNativeFields]) {
1124 // If some options have already been set before the handle existed, copy
1125 // those (and only those) that have manually been set over.
1126 this[kNativeFields].copyAssigned(handle.fields);
1127 }
1128
1129 this[kNativeFields] = handle.fields;
1130
1131 if (socket.encrypted) {
1132 this[kAlpnProtocol] = socket.alpnProtocol;
1133 this[kEncrypted] = true;
1134 } else {
1135 // 'h2c' is the protocol identifier for HTTP/2 over plain-text. We use
1136 // it here to identify any session that is not explicitly using an
1137 // encrypted socket.
1138 this[kAlpnProtocol] = 'h2c';
1139 this[kEncrypted] = false;
1140 }
1141
1142 if (isUint32(options.maxSessionInvalidFrames)) {
1143 const uint32 = new Uint32Array(
1144 this[kNativeFields].buffer, kSessionMaxInvalidFrames, 1);
1145 uint32[0] = options.maxSessionInvalidFrames;
1146 }
1147
1148 if (isUint32(options.maxSessionRejectedStreams)) {
1149 const uint32 = new Uint32Array(
1150 this[kNativeFields].buffer, kSessionMaxRejectedStreams, 1);
1151 uint32[0] = options.maxSessionRejectedStreams;
1152 }

Callers

nothing calls this directly

Calls 8

debugSessionFunction · 0.85
updateOptionsBufferFunction · 0.85
settingsMethod · 0.80
assertFunction · 0.50
isUint32Function · 0.50
consumeMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…