Add compatibility overloads for listenTCP.
This commit is contained in:
parent
e88d2d1b4b
commit
84a21f7e9d
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue