Smartdev: increase time allowed for calibre to scan for connections. Always attempt port 9090 first when allocating a random port.

This commit is contained in:
Charles Haley 2012-12-06 10:30:45 +01:00
parent 4a4a540699
commit 25bae6e580

View File

@ -54,6 +54,8 @@ def synchronous(tlockname):
class ConnectionListener (Thread): class ConnectionListener (Thread):
NOT_SERVICED_COUNT = 6
def __init__(self, driver): def __init__(self, driver):
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
@ -78,8 +80,8 @@ class ConnectionListener (Thread):
if not self.driver.connection_queue.empty(): if not self.driver.connection_queue.empty():
queue_not_serviced_count += 1 queue_not_serviced_count += 1
if queue_not_serviced_count >= 3: if queue_not_serviced_count >= self.NOT_SERVICED_COUNT:
self.driver._debug('queue not serviced') self.driver._debug('queue not serviced', queue_not_serviced_count)
try: try:
sock = self.driver.connection_queue.get_nowait() sock = self.driver.connection_queue.get_nowait()
s = self.driver._json_encode( s = self.driver._json_encode(
@ -1281,10 +1283,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self._close_listen_socket() self._close_listen_socket()
return message return message
else: else:
while i < 100: # try up to 100 random port numbers while i < 100: # try 9090 then up to 99 random port numbers
i += 1 i += 1
port = self._attach_to_port(self.listen_socket, port = self._attach_to_port(self.listen_socket,
random.randint(8192, 32000)) 9090 if i == 1 else random.randint(8192, 32000))
if port != 0: if port != 0:
break break
if port == 0: if port == 0: