MCPcopy Create free account
hub / github.com/nodejs/node / #createStream

Method #createStream

lib/internal/quic/quic.js:3237–3312  ·  view source on GitHub ↗

* @param {number} direction * @param {OpenStreamOptions} options * @returns {QuicStream}

(direction, options = kEmptyObject)

Source from the content-addressed store, hash-verified

3235 * @returns {QuicStream}
3236 */
3237 async #createStream(direction, options = kEmptyObject) {
3238 const inner = this.#inner;
3239 if (this.#isClosedOrClosing) {
3240 throw new ERR_INVALID_STATE('Session is closed. New streams cannot be opened.');
3241 }
3242 const dir = direction === kStreamDirectionBidirectional ? 'bidi' : 'uni';
3243 if (inner.state.isStreamOpenAllowed) {
3244 debug(`opening new pending ${dir} stream`);
3245 } else {
3246 debug(`opening new ${dir} stream`);
3247 }
3248
3249 validateObject(options, 'options');
3250 const {
3251 body,
3252 priority = 'default',
3253 incremental = false,
3254 highWaterMark = kDefaultHighWaterMark,
3255 headers,
3256 onheaders,
3257 ontrailers,
3258 oninfo,
3259 onwanttrailers,
3260 } = options;
3261
3262 validateOneOf(priority, 'options.priority', ['default', 'low', 'high']);
3263 validateBoolean(incremental, 'options.incremental');
3264
3265 const validatedBody = validateBody(body);
3266
3267 const handle = this.#handle.openStream(direction, validatedBody);
3268 if (handle === undefined) {
3269 throw new ERR_QUIC_OPEN_STREAM_FAILED();
3270 }
3271
3272 if (inner.state.isPrioritySupported) {
3273 const urgency = priority === 'high' ? 0 : priority === 'low' ? 7 : 3;
3274 handle.setPriority((urgency << 1) | (incremental ? 1 : 0));
3275 }
3276
3277 const stream = new QuicStream(
3278 kPrivateConstructor, handle, this, direction, true /* isLocal */);
3279 inner.streams.add(stream);
3280 if (typeof this.#inner.onerror === 'function') {
3281 markPromiseAsHandled(stream.closed);
3282 }
3283
3284 // If the body was a FileHandle, store it on the stream so it is
3285 // closed automatically when the stream finishes.
3286 if (FileHandle.isFileHandle(body)) {
3287 stream[kAttachFileHandle](body);
3288 }
3289
3290 // Set the high water mark for backpressure.
3291 stream.highWaterMark = highWaterMark;
3292
3293 // Set stream callbacks before sending headers to avoid missing events.
3294 if (onheaders) stream.onheaders = onheaders;

Callers 2

Calls 7

sendHeadersMethod · 0.95
validateBodyFunction · 0.85
isFileHandleMethod · 0.80
setPriorityMethod · 0.65
addMethod · 0.65
debugFunction · 0.50
publishMethod · 0.45

Tested by

no test coverage detected