Add class variable allow_reuse_address in TCPServer -- if nonzero, the

server_bind() method calls setsockopt(SOL_SOCKET, SO_REUSEADDR, 1).
This commit is contained in:
Guido van Rossum 2000-05-09 14:53:29 +00:00
parent fd4114e7b8
commit e3c7a5fbf5

View File

@ -141,6 +141,7 @@ class TCPServer:
- address_family
- socket_type
- request_queue_size (only for stream sockets)
- reuse_address
Instance variables:
@ -156,6 +157,8 @@ class TCPServer:
request_queue_size = 5
allow_reuse_address = 0
def __init__(self, server_address, RequestHandlerClass):
"""Constructor. May be extended, do not override."""
self.server_address = server_address
@ -171,6 +174,8 @@ class TCPServer:
May be overridden.
"""
if self.allow_reuse_address:
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
def server_activate(self):