Bug 1240610 - Align socket_timeout with Python's socket interface; r?automatedtester
When socket.settimeout(None) is set in Python's standard library this
is meant to be equivalent to disabling timeouts on socket operations.
marionette.transport should respect this.
This change set unbreaks the use of the --jdebugger flag to `./mach
marionette-test'.
--- a/testing/marionette/transport/marionette_transport/transport.py
+++ b/testing/marionette/transport/marionette_transport/transport.py
@@ -111,16 +111,20 @@ class TcpTransport(object):
On top of this protocol it uses a Marionette message format, that
depending on the protocol level offered by the remote server, varies.
Supported protocol levels are 1 and above.
"""
max_packet_length = 4096
connection_lost_msg = "Connection to Marionette server is lost. Check gecko.log (desktop firefox) or logcat (b2g) for errors."
def __init__(self, addr, port, socket_timeout=360.0):
+ """If `socket_timeout` is `0` or `0.0`, non-blocking socket mode
+ will be used. Setting it to `1` or `None` disables timeouts on
+ socket operations altogether.
+ """
self.addr = addr
self.port = port
self.socket_timeout = socket_timeout
self.protocol = 1
self.application_type = None
self.last_id = 0
self.expected_responses = []
@@ -159,17 +163,17 @@ class TcpTransport(object):
:param unmarshal: Default is to deserialise the packet and
return a ``Message`` type. Setting this to false will return
the raw packet.
"""
now = time.time()
data = ""
bytes_to_recv = 10
- while time.time() - now < self.socket_timeout:
+ while self.socket_timeout is None or (time.time() - now < self.socket_timeout):
try:
chunk = self.sock.recv(bytes_to_recv)
data += chunk
except socket.timeout:
pass
else:
if not chunk:
raise IOError(self.connection_lost_msg)