mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Add a close_request method to the BaseServer so that the TCPServer class
can close the request connection when it's done handling it.
This commit is contained in:
parent
3f5cc20813
commit
285a7e59f3
1 changed files with 14 additions and 0 deletions
|
@ -154,6 +154,7 @@ class BaseServer:
|
||||||
- verify_request(request, client_address)
|
- verify_request(request, client_address)
|
||||||
- server_close()
|
- server_close()
|
||||||
- process_request(request, client_address)
|
- process_request(request, client_address)
|
||||||
|
- close_request(request)
|
||||||
- handle_error()
|
- handle_error()
|
||||||
|
|
||||||
Methods for derived classes:
|
Methods for derived classes:
|
||||||
|
@ -214,6 +215,7 @@ class BaseServer:
|
||||||
self.process_request(request, client_address)
|
self.process_request(request, client_address)
|
||||||
except:
|
except:
|
||||||
self.handle_error(request, client_address)
|
self.handle_error(request, client_address)
|
||||||
|
self.close_request(request)
|
||||||
|
|
||||||
def verify_request(self, request, client_address):
|
def verify_request(self, request, client_address):
|
||||||
"""Verify the request. May be overridden.
|
"""Verify the request. May be overridden.
|
||||||
|
@ -243,6 +245,10 @@ class BaseServer:
|
||||||
"""Finish one request by instantiating RequestHandlerClass."""
|
"""Finish one request by instantiating RequestHandlerClass."""
|
||||||
self.RequestHandlerClass(request, client_address, self)
|
self.RequestHandlerClass(request, client_address, self)
|
||||||
|
|
||||||
|
def close_request(self, request):
|
||||||
|
"""Called to clean up an individual request."""
|
||||||
|
pass
|
||||||
|
|
||||||
def handle_error(self, request, client_address):
|
def handle_error(self, request, client_address):
|
||||||
"""Handle an error gracefully. May be overridden.
|
"""Handle an error gracefully. May be overridden.
|
||||||
|
|
||||||
|
@ -277,6 +283,7 @@ class TCPServer(BaseServer):
|
||||||
- get_request() -> request, client_address
|
- get_request() -> request, client_address
|
||||||
- verify_request(request, client_address)
|
- verify_request(request, client_address)
|
||||||
- process_request(request, client_address)
|
- process_request(request, client_address)
|
||||||
|
- close_request(request)
|
||||||
- handle_error()
|
- handle_error()
|
||||||
|
|
||||||
Methods for derived classes:
|
Methods for derived classes:
|
||||||
|
@ -357,6 +364,10 @@ class TCPServer(BaseServer):
|
||||||
"""
|
"""
|
||||||
return self.socket.accept()
|
return self.socket.accept()
|
||||||
|
|
||||||
|
def close_request(self, request):
|
||||||
|
"""Called to clean up an individual request."""
|
||||||
|
request.close()
|
||||||
|
|
||||||
|
|
||||||
class UDPServer(TCPServer):
|
class UDPServer(TCPServer):
|
||||||
|
|
||||||
|
@ -376,6 +387,9 @@ class UDPServer(TCPServer):
|
||||||
# No need to call listen() for UDP.
|
# No need to call listen() for UDP.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def close_request(self, request):
|
||||||
|
# No need to close anything.
|
||||||
|
pass
|
||||||
|
|
||||||
class ForkingMixIn:
|
class ForkingMixIn:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue