mirror of https://github.com/python/cpython.git
bpo-16594: Add allow_reuse_port on socketserver (GH-30072)
* bpo-16594: Add allow_reuse_port on socketserver * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
481f3ffdbe
commit
b56774bd93
|
@ -187,6 +187,7 @@ class BaseServer:
|
|||
- address_family
|
||||
- socket_type
|
||||
- allow_reuse_address
|
||||
- allow_reuse_port
|
||||
|
||||
Instance variables:
|
||||
|
||||
|
@ -425,6 +426,7 @@ class TCPServer(BaseServer):
|
|||
- socket_type
|
||||
- request_queue_size (only for stream sockets)
|
||||
- allow_reuse_address
|
||||
- allow_reuse_port
|
||||
|
||||
Instance variables:
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -519,6 +525,8 @@ class UDPServer(TCPServer):
|
|||
|
||||
allow_reuse_address = False
|
||||
|
||||
allow_reuse_port = False
|
||||
|
||||
socket_type = socket.SOCK_DGRAM
|
||||
|
||||
max_packet_size = 8192
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Add allow allow_reuse_port flag in socketserver.
|
Loading…
Reference in New Issue