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