Add compatibility overloads for listenTCP.

This commit is contained in:
Sönke Ludwig 2017-01-30 09:19:08 +01:00
parent e88d2d1b4b
commit 84a21f7e9d
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -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.