| 8227 | } |
| 8228 | function emitDrain(client) { |
| 8229 | client[kNeedDrain] = 0; |
| 8230 | client.emit("drain", client[kUrl], [client]); |
| 8231 | } |
| 8232 | function resume(client, sync) { |
| 8233 | if (client[kResuming] === 2) { |
| 8234 | return; |
| 8235 | } |
| 8236 | client[kResuming] = 2; |
| 8237 | _resume(client, sync); |
| 8238 | client[kResuming] = 0; |
| 8239 | if (client[kRunningIdx] > 256) { |
| 8240 | client[kQueue].splice(0, client[kRunningIdx]); |
| 8241 | client[kPendingIdx] -= client[kRunningIdx]; |
| 8242 | client[kRunningIdx] = 0; |
| 8243 | } |
| 8244 | } |
| 8245 | function _resume(client, sync) { |
| 8246 | var _a; |
| 8247 | while (true) { |
| 8248 | if (client.destroyed) { |
| 8249 | assert(client[kPending] === 0); |
| 8250 | return; |
| 8251 | } |
| 8252 | if (client[kClosedResolve] && !client[kSize]) { |
| 8253 | client[kClosedResolve](); |
| 8254 | client[kClosedResolve] = null; |
| 8255 | return; |
| 8256 | } |
| 8257 | if (client[kHTTPContext]) { |
| 8258 | client[kHTTPContext].resume(); |
| 8259 | } |
| 8260 | if (client[kBusy]) { |
| 8261 | client[kNeedDrain] = 2; |
| 8262 | } else if (client[kNeedDrain] === 2) { |
| 8263 | if (sync) { |
| 8264 | client[kNeedDrain] = 1; |
| 8265 | queueMicrotask(() => emitDrain(client)); |
| 8266 | } else { |
| 8267 | emitDrain(client); |
| 8268 | } |
| 8269 | continue; |
| 8270 | } |
| 8271 | if (client[kPending] === 0) { |
| 8272 | return; |
| 8273 | } |
| 8274 | if (client[kRunning] >= (getPipelining(client) || 1)) { |
| 8275 | return; |
| 8276 | } |
| 8277 | const request = client[kQueue][client[kPendingIdx]]; |
| 8278 | if (client[kUrl].protocol === "https:" && client[kServerName] !== request.servername) { |
| 8279 | if (client[kRunning] > 0) { |
| 8280 | return; |
| 8281 | } |
| 8282 | client[kServerName] = request.servername; |
| 8283 | (_a = client[kHTTPContext]) == null ? void 0 : _a.destroy(new InformationalError("servername changed"), () => { |
| 8284 | client[kHTTPContext] = null; |
| 8285 | resume(client); |
| 8286 | }); |