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

Function Socket

lib/net.js:485–651  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

483}
484
485function Socket(options) {
486 if (!(this instanceof Socket)) return new Socket(options);
487 if (options?.objectMode) {
488 throw new ERR_INVALID_ARG_VALUE(
489 'options.objectMode',
490 options.objectMode,
491 'is not supported',
492 );
493 } else if (options?.readableObjectMode || options?.writableObjectMode) {
494 throw new ERR_INVALID_ARG_VALUE(
495 `options.${
496 options.readableObjectMode ? 'readableObjectMode' : 'writableObjectMode'
497 }`,
498 options.readableObjectMode || options.writableObjectMode,
499 'is not supported',
500 );
501 }
502 if (options?.keepAliveInitialDelay !== undefined) {
503 validateNumber(
504 options?.keepAliveInitialDelay, 'options.keepAliveInitialDelay',
505 );
506
507 if (options.keepAliveInitialDelay < 0) {
508 options.keepAliveInitialDelay = 0;
509 }
510 }
511
512 this.connecting = false;
513 // Problem with this is that users can supply their own handle, that may not
514 // have _handle.getAsyncId(). In this case an[async_id_symbol] should
515 // probably be supplied by async_hooks.
516 this[async_id_symbol] = -1;
517 this._hadError = false;
518 this[kHandle] = null;
519 this._parent = null;
520 this._host = null;
521 this[kLastWriteQueueSize] = 0;
522 this[kTimeout] = null;
523 this[kBuffer] = null;
524 this[kBufferCb] = null;
525 this[kBufferGen] = null;
526 this._closeAfterHandlingError = false;
527
528 if (typeof options === 'number')
529 options = { fd: options }; // Legacy interface.
530 else
531 options = { ...options };
532
533 // Default to *not* allowing half open sockets.
534 options.allowHalfOpen = Boolean(options.allowHalfOpen);
535 // For backwards compat do not emit close on destroy.
536 options.emitClose = false;
537 options.autoDestroy = true;
538 // Handle strings directly.
539 options.decodeStrings = false;
540 stream.Duplex.call(this, options);
541
542 // An adopted BoundSocket is bound but not connected: defer the read flow

Callers

nothing calls this directly

Calls 13

getNewAsyncIdFunction · 0.85
makeSyncWriteFunction · 0.85
isUint8ArrayFunction · 0.85
initSocketHandleFunction · 0.85
getAsyncIdMethod · 0.80
isBlockListMethod · 0.80
createHandleFunction · 0.70
openMethod · 0.65
callMethod · 0.45
onMethod · 0.45
readStopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…