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

Function Socket

lib/dgram.js:110–187  ·  view source on GitHub ↗
(type, listener)

Source from the content-addressed store, hash-verified

108}
109
110function Socket(type, listener) {
111 FunctionPrototypeCall(EventEmitter, this);
112 let lookup;
113 let recvBufferSize;
114 let sendBufferSize;
115 let receiveBlockList;
116 let sendBlockList;
117
118 let options;
119 if (type !== null && typeof type === 'object') {
120 options = type;
121 type = options.type;
122 lookup = options.lookup;
123 if (options.recvBufferSize) {
124 validateUint32(options.recvBufferSize, 'options.recvBufferSize');
125 }
126 if (options.sendBufferSize) {
127 validateUint32(options.sendBufferSize, 'options.sendBufferSize');
128 }
129 recvBufferSize = options.recvBufferSize;
130 sendBufferSize = options.sendBufferSize;
131 if (options.receiveBlockList) {
132 if (!lazyLoadBlockList().isBlockList(options.receiveBlockList)) {
133 throw new ERR_INVALID_ARG_TYPE('options.receiveBlockList', 'net.BlockList', options.receiveBlockList);
134 }
135 receiveBlockList = options.receiveBlockList;
136 }
137 if (options.sendBlockList) {
138 if (!lazyLoadBlockList().isBlockList(options.sendBlockList)) {
139 throw new ERR_INVALID_ARG_TYPE('options.sendBlockList', 'net.BlockList', options.sendBlockList);
140 }
141 sendBlockList = options.sendBlockList;
142 }
143 }
144
145 const handle = newHandle(type, lookup);
146 handle[owner_symbol] = this;
147
148 this[async_id_symbol] = handle.getAsyncId();
149 this.type = type;
150
151 if (typeof listener === 'function')
152 this.on('message', listener);
153
154 this[kStateSymbol] = {
155 handle,
156 receiving: false,
157 bindState: BIND_STATE_UNBOUND,
158 connectState: CONNECT_STATE_DISCONNECTED,
159 queue: undefined,
160 reuseAddr: options?.reuseAddr, // Use UV_UDP_REUSEADDR if true.
161 reusePort: options?.reusePort,
162 ipv6Only: options?.ipv6Only,
163 recvBufferSize,
164 sendBufferSize,
165 receiveBlockList,
166 sendBlockList,
167 };

Callers

nothing calls this directly

Calls 10

lazyLoadBlockListFunction · 0.85
newHandleFunction · 0.85
validateAbortSignalFunction · 0.85
isBlockListMethod · 0.80
getAsyncIdMethod · 0.80
onAbortedFunction · 0.70
addAbortListenerFunction · 0.50
onMethod · 0.45
onceMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…