(req)
| 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) { |
no test coverage detected