From 84a21f7e9d05dc5f0c2bb377c866699e48612efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 30 Jan 2017 09:19:08 +0100 Subject: [PATCH] Add compatibility overloads for listenTCP. --- source/vibe/core/net.d | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index cd5ab90..b21ab12 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -108,9 +108,35 @@ TCPListener listenTCP(ushort port, TCPConnectionDelegate connection_callback, st auto conn = TCPConnection(s, addr); runTask(connection_callback, conn); }); + enforce(sock != StreamListenSocketFD.invalid, "Failed to listen on %s", address); return TCPListener(sock); } +/// Compatibility overload - use an `@safe nothrow` callback instead. +deprecated("Use a @safe nothrow callback instead.") +TCPListener[] listenTCP(ushort port, void delegate(TCPConnection) connection_callback, TCPListenOptions options = TCPListenOptions.defaults) +{ + TCPListener[] ret; + try ret ~= listenTCP(port, connection_callback, "::", options); + catch (Exception e) logDiagnostic("Failed to listen on \"::\": %s", e.msg); + try ret ~= listenTCP(port, connection_callback, "0.0.0.0", options); + catch (Exception e) logDiagnostic("Failed to listen on \"0.0.0.0\": %s", e.msg); + enforce(ret.length > 0, format("Failed to listen on all interfaces on port %s", port)); + return ret; +} +/// ditto +deprecated("Use a @safe nothrow callback instead.") +TCPListener listenTCP(ushort port, void delegate(TCPConnection) connection_callback, string address, TCPListenOptions options = TCPListenOptions.defaults) +{ + return listenTCP(port, (conn) @trusted nothrow { + try connection_callback(conn); + catch (Exception e) { + logError("Handling of connection failed: %s", e.msg); + conn.close(); + } + }, address, options); +} + /** Starts listening on the specified port.