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

Method doShutdown

lib/internal/js_stream_socket.js:127–162  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

125 }
126
127 doShutdown(req) {
128 // TODO(addaleax): It might be nice if we could get into a state where
129 // DoShutdown() is not called on streams while a write is still pending.
130 //
131 // Currently, the only part of the code base where that happens is the
132 // TLS implementation, which calls both DoWrite() and DoShutdown() on the
133 // underlying network stream inside of its own DoShutdown() method.
134 // Working around that on the native side is not quite trivial (yet?),
135 // so for now that is supported here.
136
137 if (this[kCurrentWriteRequest] !== null) {
138 this[kPendingShutdownRequest] = req;
139 return 0;
140 }
141
142 assert(this[kCurrentWriteRequest] === null);
143 assert(this[kCurrentShutdownRequest] === null);
144 this[kCurrentShutdownRequest] = req;
145
146 if (this[kPendingClose]) {
147 // If doClose is pending, the stream & this._handle are gone. We can't do
148 // anything. doClose will call finishShutdown with ECANCELED for us shortly.
149 return 0;
150 }
151
152 const handle = this._handle;
153 assert(handle !== null);
154
155 process.nextTick(() => {
156 // Ensure that write is dispatched asynchronously.
157 this.stream.end(() => {
158 this.finishShutdown(handle, 0);
159 });
160 });
161 return 0;
162 }
163
164 // handle === this._handle except when called from doClose().
165 finishShutdown(handle, errCode) {

Callers 2

finishWriteMethod · 0.95
onshutdownFunction · 0.80

Calls 3

finishShutdownMethod · 0.95
assertFunction · 0.70
endMethod · 0.45

Tested by

no test coverage detected