* @param {http2.Http2Server} http2Server * @returns {() => void}
(http2Server)
| 401 | * @returns {() => void} |
| 402 | */ |
| 403 | function createCloseHttp2SessionsByHttp2Server (http2Server) { |
| 404 | /** |
| 405 | * @type {Set<http2.Http2Session>} |
| 406 | */ |
| 407 | http2Server[kHttp2ServerSessions] = new Set() |
| 408 | |
| 409 | http2Server.on(class="st">'session', function (session) { |
| 410 | session.once(class="st">'connect', function () { |
| 411 | http2Server[kHttp2ServerSessions].add(session) |
| 412 | }) |
| 413 | |
| 414 | session.once(class="st">'close', function () { |
| 415 | http2Server[kHttp2ServerSessions].delete(session) |
| 416 | }) |
| 417 | |
| 418 | session.once(class="st">'frameError', function (type, code, streamId) { |
| 419 | if (streamId === 0) { |
| 420 | class="cm">// The stream ID is 0, which means that the error is related to the session itself. |
| 421 | class="cm">// If the event is not associated with a stream, the Http2Session will be shut down immediately |
| 422 | http2Server[kHttp2ServerSessions].delete(session) |
| 423 | } |
| 424 | }) |
| 425 | |
| 426 | session.once(class="st">'goaway', function () { |
| 427 | class="cm">// The Http2Session instance will be shut down automatically when the class="st">'goaway' event is emitted. |
| 428 | http2Server[kHttp2ServerSessions].delete(session) |
| 429 | }) |
| 430 | }) |
| 431 | |
| 432 | return function closeHttp2Sessions () { |
| 433 | if (http2Server[kHttp2ServerSessions].size === 0) { |
| 434 | return |
| 435 | } |
| 436 | |
| 437 | for (const session of http2Server[kHttp2ServerSessions]) { |
| 438 | session.close() |
| 439 | } |
| 440 | } |
| 441 | } |
no test coverage detected