From 25bae6e580c794d83eae6feb24e38b9418ac488f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 6 Dec 2012 10:30:45 +0100 Subject: [PATCH] Smartdev: increase time allowed for calibre to scan for connections. Always attempt port 9090 first when allocating a random port. --- src/calibre/devices/smart_device_app/driver.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index be7f5012c5..a9df1c0d94 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -54,6 +54,8 @@ def synchronous(tlockname): class ConnectionListener (Thread): + NOT_SERVICED_COUNT = 6 + def __init__(self, driver): Thread.__init__(self) self.daemon = True @@ -78,8 +80,8 @@ class ConnectionListener (Thread): if not self.driver.connection_queue.empty(): queue_not_serviced_count += 1 - if queue_not_serviced_count >= 3: - self.driver._debug('queue not serviced') + if queue_not_serviced_count >= self.NOT_SERVICED_COUNT: + self.driver._debug('queue not serviced', queue_not_serviced_count) try: sock = self.driver.connection_queue.get_nowait() s = self.driver._json_encode( @@ -1281,10 +1283,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self._close_listen_socket() return message 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 port = self._attach_to_port(self.listen_socket, - random.randint(8192, 32000)) + 9090 if i == 1 else random.randint(8192, 32000)) if port != 0: break if port == 0: