Skip to content

Commit

Permalink
Add way to disable port and address reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
rracariu authored and Radu Racariu committed Apr 17, 2019
1 parent 4a828ae commit f5450c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions http/vibe/http/server.d
Expand Up @@ -531,7 +531,8 @@ private enum HTTPServerOptionImpl {
none = 0,
errorStackTraces = 1<<7,
reusePort = 1<<8,
distribute = 1<<9 // deprecated
distribute = 1<<9, // deprecated
reuseAddress = 1<<10
}

// TODO: Should be turned back into an enum once the deprecated symbols can be removed
Expand Down Expand Up @@ -585,13 +586,15 @@ struct HTTPServerOption {
static enum errorStackTraces = HTTPServerOptionImpl.errorStackTraces;
/// Enable port reuse in `listenTCP()`
static enum reusePort = HTTPServerOptionImpl.reusePort;
/// Enable address reuse in `listenTCP()`
static enum reuseAddress = HTTPServerOptionImpl.reuseAddress;

/** The default set of options.
Includes all parsing options, as well as the `errorStackTraces`
option if the code is compiled in debug mode.
*/
static enum defaults = () { debug return HTTPServerOptionImpl.errorStackTraces; else return HTTPServerOptionImpl.none; } ().HTTPServerOption;
static enum defaults = () { debug return HTTPServerOptionImpl.errorStackTraces; else return HTTPServerOptionImpl.reuseAddress; } ().HTTPServerOption;

deprecated("None has been renamed to none.")
static enum None = none;
Expand Down Expand Up @@ -2000,10 +2003,11 @@ private HTTPListener listenHTTPPlain(HTTPServerSettings settings, HTTPServerRequ
import vibe.core.core : runWorkerTaskDist;
import std.algorithm : canFind, find;

static TCPListener doListen(HTTPServerContext listen_info, bool dist, bool reusePort, bool is_tls)
static TCPListener doListen(HTTPServerContext listen_info, bool dist, bool reusePort, bool reuseAddress, bool is_tls)
@safe {
try {
TCPListenOptions options = TCPListenOptions.defaults;
if(reuseAddress) options |= TCPListenOptions.reuseAddress; else options &= ~TCPListenOptions.reuseAddress;
if(reusePort) options |= TCPListenOptions.reusePort; else options &= ~TCPListenOptions.reusePort;
auto ret = listenTCP(listen_info.bindPort, (TCPConnection conn) nothrow @safe {
try handleHTTPConnection(conn, listen_info);
Expand Down Expand Up @@ -2044,6 +2048,7 @@ private HTTPListener listenHTTPPlain(HTTPServerSettings settings, HTTPServerRequ
if (auto tcp_lst = doListen(li,
(settings.options & HTTPServerOptionImpl.distribute) != 0,
(settings.options & HTTPServerOption.reusePort) != 0,
(settings.options & HTTPServerOption.reuseAddress) != 0,
settings.tlsContext !is null)) // DMD BUG 2043
{
li.m_listener = tcp_lst;
Expand Down

0 comments on commit f5450c4

Please sign in to comment.