MCPcopy
hub / github.com/socketio/socket.io / close

Method close

packages/engine.io/lib/socket.ts:559–585  ·  packages/engine.io/lib/socket.ts::Socket.close

* Closes the socket and underlying transport. * * @param {Boolean} discard - optional, discard the transport * @return {Socket} for chaining

(discard?: boolean)

Source from the content-addressed store, hash-verified

557 * @return {Socket} for chaining
558 */
559 public close(discard?: boolean) {
560 if (
561 discard &&
562 (this.readyState === class="st">"open" || this.readyState === class="st">"closing")
563 ) {
564 return this.closeTransport(discard);
565 }
566
567 if (class="st">"open" !== this.readyState) return;
568
569 this.readyState = class="st">"closing";
570
571 if (this.writeBuffer.length) {
572 debug(
573 class="st">"there are %d remaining packets in the buffer, waiting for the 'drain' event",
574 this.writeBuffer.length,
575 );
576 this.once(class="st">"drain", () => {
577 debug(class="st">"all packets have been sent, closing the transport");
578 this.closeTransport(discard);
579 });
580 return;
581 }
582
583 debug(class="st">"the buffer is empty, closing the transport right away");
584 this.closeTransport(discard);
585 }
586
587 /**
588 * Closes the underlying transport.

Callers 15

_maybeUpgradeMethod · 0.45
onPacketMethod · 0.45
onErrorMethod · 0.45
clearTransportMethod · 0.45
closeTransportMethod · 0.45
callbackMethod · 0.45
closeFunction · 0.45
onWebTransportSessionFunction · 0.45
closeSessionFunction · 0.45
initMethod · 0.45
cleanupMethod · 0.45
onWebSocketMethod · 0.45

Calls 2

closeTransportMethod · 0.95
debugFunction · 0.85

Tested by

no test coverage detected