Avoid socket leaks in examples.

This commit is contained in:
Sönke Ludwig 2020-11-25 23:23:58 +01:00
parent 958856f6f1
commit a44d3f2655
2 changed files with 9 additions and 2 deletions

View file

@ -5,10 +5,16 @@ import vibe.core.stream : pipe;
void main()
{
listenTCP(7000, (conn) @safe nothrow {
auto listeners = listenTCP(7000, (conn) @safe nothrow {
try pipe(conn, conn);
catch (Exception e)
logError("Error: %s", e.msg);
});
// closes the listening sockets
scope (exit)
foreach (l; listeners)
l.stopListening();
runApplication();
}