From f36ff1cca59dd7f43d85dd14ed2c613e7b954928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 28 Jun 2024 09:10:15 +0200 Subject: [PATCH] Fix HTTP listener teardown in HTTP2 example. --- examples/http2/source/app.d | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/http2/source/app.d b/examples/http2/source/app.d index 2082b43..1aa834c 100644 --- a/examples/http2/source/app.d +++ b/examples/http2/source/app.d @@ -44,20 +44,21 @@ void main() { //import vibe.core.log; //setLogLevel(LogLevel.trace); + HTTPListener[] listeners; /* ==== cleartext HTTP/2 support (h2c) ==== */ auto settings = new HTTPServerSettings; settings.port = 8090; settings.bindAddresses = ["127.0.0.1"]; settings.options |= HTTPServerOption.enableHTTP2; - listenHTTP(settings, &handleReq); + listeners ~= listenHTTP(settings, &handleReq); /* ==== cleartext HTTP/2 support (h2c) with a heavy DATA frame ==== */ auto bigSettings = new HTTPServerSettings; bigSettings.port = 8092; bigSettings.bindAddresses = ["127.0.0.1"]; bigSettings.options |= HTTPServerOption.enableHTTP2; - listenHTTP(bigSettings, &bigHandleReq!100000); + listeners ~= listenHTTP(bigSettings, &bigHandleReq!100000); /* ========== HTTPS (h2) support ========== */ auto tlsSettings = new HTTPServerSettings; @@ -72,7 +73,7 @@ void main() // set alpn callback to support HTTP/2 protocol negotiation tlsSettings.tlsContext.alpnCallback(http2Callback); - listenHTTP(tlsSettings, &tlsHandleReq); + listeners ~= listenHTTP(tlsSettings, &tlsHandleReq); /* ========== HTTPS (h2) support with a heavy DATA frame ========== */ auto bigTLSSettings = new HTTPServerSettings; @@ -87,8 +88,11 @@ void main() // set alpn callback to support HTTP/2 protocol negotiation bigTLSSettings.tlsContext.alpnCallback(http2Callback); - auto l = listenHTTP(bigTLSSettings, &bigHandleReq!100000); - scope(exit) l.stopListening(); + listeners ~= listenHTTP(bigTLSSettings, &bigHandleReq!100000); + + scope(exit) + foreach (l; listeners) + l.stopListening(); /* ========== Run both `listenHTTP` handlers ========== */ // UNCOMMENT to run