Add --reuse-port to make use of SO_REUSEPORT optional (#1669)

Fixes #1603
This commit is contained in:
Martin Broadhurst 2018-01-02 17:25:26 +00:00 committed by Berker Peksag
parent 5953148573
commit 6171ac4885
3 changed files with 33 additions and 1 deletions

View File

@ -428,6 +428,18 @@ to enable or disable its usage.
.. versionchanged:: 19.6
added support for the ``SENDFILE`` environment variable
.. _reuse-port:
reuse_port
~~~~~~~~~~
* ``--reuse-port``
* ``False``
Set the ``SO_REUSEPORT`` flag on the listening socket.
.. versionadded:: 19.8
.. _chdir:
chdir

View File

@ -204,6 +204,10 @@ class Config(object):
return True
@property
def reuse_port(self):
return self.settings['reuse_port'].get()
@property
def paste_global_conf(self):
raw_global_conf = self.settings['raw_paste_global_conf'].get()
@ -954,6 +958,21 @@ class Sendfile(Setting):
"""
class ReusePort(Setting):
name = "reuse_port"
section = "Server Mechanics"
cli = ["--reuse-port"]
validator = validate_bool
action = "store_true"
default = False
desc = """\
Set the ``SO_REUSEPORT`` flag on the listening socket.
.. versionadded:: 19.8
"""
class Chdir(Setting):
name = "chdir"
section = "Server Mechanics"

View File

@ -39,7 +39,8 @@ class BaseSocket(object):
def set_options(self, sock, bound=False):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, 'SO_REUSEPORT'): # pragma: no cover
if (self.conf.reuse_port
and hasattr(socket, 'SO_REUSEPORT')): # pragma: no cover
try:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except socket.error as err: