protocol: make connection timeout after some time
This commit is contained in:
parent
62619f29fb
commit
72111bce70
|
@ -222,7 +222,11 @@ class Browser:
|
|||
else:
|
||||
pass # TODO
|
||||
|
||||
response = Response.parse(req.proceed())
|
||||
data = req.proceed()
|
||||
if not data:
|
||||
self.set_status_error(f"Server did not respond in time ({url}).")
|
||||
return
|
||||
response = Response.parse(data)
|
||||
if not response:
|
||||
self.set_status_error(f"Server response parsing failed ({url}).")
|
||||
return
|
||||
|
|
|
@ -81,7 +81,7 @@ class Request:
|
|||
self.payload += LINE_TERM
|
||||
|
||||
try:
|
||||
sock = socket.create_connection((hostname, port))
|
||||
sock = socket.create_connection((hostname, port), timeout=10)
|
||||
except OSError as exc:
|
||||
self.state = Request.STATE_CONNECTION_FAILED
|
||||
self.error = exc.strerror
|
||||
|
@ -124,7 +124,10 @@ class Request:
|
|||
self.ssock.sendall(self.payload)
|
||||
response = b""
|
||||
while True:
|
||||
buf = self.ssock.recv(4096)
|
||||
try:
|
||||
buf = self.ssock.recv(4096)
|
||||
except socket.timeout:
|
||||
buf = None
|
||||
if not buf:
|
||||
return response
|
||||
response += buf
|
||||
|
|
Reference in a new issue