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

Method doClose

lib/internal/js_stream_socket.js:242–266  ·  view source on GitHub ↗
(cb)

Source from the content-addressed store, hash-verified

240 }
241
242 doClose(cb) {
243 this[kPendingClose] = true;
244
245 const handle = this._handle;
246
247 // When sockets of the "net" module destroyed, they will call
248 // `this._handle.close()` which will also emit EOF if not emitted before.
249 // This feature makes sockets on the other side emit "end" and "close"
250 // even though we haven't called `end()`. As `stream` are likely to be
251 // instances of `net.Socket`, calling `stream.destroy()` manually will
252 // avoid issues that don't properly close wrapped connections.
253 this.stream.destroy();
254
255 setImmediate(() => {
256 // Should be already set by net.js
257 assert(this._handle === null);
258
259 this.finishWrite(handle, uv.UV_ECANCELED);
260 this.finishShutdown(handle, uv.UV_ECANCELED);
261
262 this[kPendingClose] = false;
263
264 cb();
265 });
266 }
267
268 get [kBoundSession]() {
269 return this.stream[kBoundSession];

Callers 1

constructorMethod · 0.95

Calls 6

finishWriteMethod · 0.95
finishShutdownMethod · 0.95
assertFunction · 0.70
setImmediateFunction · 0.50
cbFunction · 0.50
destroyMethod · 0.45

Tested by

no test coverage detected