Skip to content

bpo-16594: Add allow_reuse_port on socketserver #30072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/socketserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class BaseServer:
- address_family
- socket_type
- allow_reuse_address
- allow_reuse_port

Instance variables:

Expand Down Expand Up @@ -425,6 +426,7 @@ class TCPServer(BaseServer):
- socket_type
- request_queue_size (only for stream sockets)
- allow_reuse_address
- allow_reuse_port

Instance variables:

Expand All @@ -442,6 +444,8 @@ class TCPServer(BaseServer):

allow_reuse_address = False

allow_reuse_port = False

def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
"""Constructor. May be extended, do not override."""
BaseServer.__init__(self, server_address, RequestHandlerClass)
Expand All @@ -463,6 +467,8 @@ def server_bind(self):
"""
if self.allow_reuse_address:
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if self.allow_reuse_port:
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname()

Expand Down Expand Up @@ -519,6 +525,8 @@ class UDPServer(TCPServer):

allow_reuse_address = False

allow_reuse_port = False

socket_type = socket.SOCK_DGRAM

max_packet_size = 8192
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add allow allow_reuse_port flag in socketserver.