]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-16594: Add allow_reuse_port on socketserver (GH-30072)
authorAN Long <aisk@users.noreply.github.com>
Mon, 13 Dec 2021 12:14:17 +0000 (12:14 +0000)
committerGitHub <noreply@github.com>
Mon, 13 Dec 2021 12:14:17 +0000 (14:14 +0200)
* 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>
Lib/socketserver.py
Misc/NEWS.d/next/Library/2021-12-12-13-41-47.bpo-16594.yfC7L4.rst [new file with mode: 0644]

index 0d9583d56a4d742aa04b075426cdb66b781ef0c5..5e070bc3912af3ca9b53fa689d6eacd43ec50a55 100644 (file)
@@ -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 @@ class TCPServer(BaseServer):
         """
         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
diff --git a/Misc/NEWS.d/next/Library/2021-12-12-13-41-47.bpo-16594.yfC7L4.rst b/Misc/NEWS.d/next/Library/2021-12-12-13-41-47.bpo-16594.yfC7L4.rst
new file mode 100644 (file)
index 0000000..a977a6b
--- /dev/null
@@ -0,0 +1 @@
+Add allow allow_reuse_port flag in socketserver.
\ No newline at end of file