[gnome-keysign: 26/65] bluetoothoffer: select wait for 0.5 second and remove defer for accept



commit 0e8b20e4780e7ff7924f40907c9f52e41b73f19e
Author: RyuzakiKK <aasonykk gmail com>
Date:   Sun Aug 20 16:17:38 2017 +0200

    bluetoothoffer: select wait for 0.5 second and remove defer for accept
    
    Instead of the implicit "True" now we explicitly wait for half a second.
    This should also provide a small responsiveness improvement.

 keysign/bluetoothoffer.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/keysign/bluetoothoffer.py b/keysign/bluetoothoffer.py
index 8421e3d..590da35 100644
--- a/keysign/bluetoothoffer.py
+++ b/keysign/bluetoothoffer.py
@@ -53,9 +53,11 @@ class BluetoothOffer:
                 # server_socket.accept() is not stoppable. So with select we can call accept()
                 # only when we are sure that there is already a waiting connection
                 ready_to_read, ready_to_write, in_error = yield threads.deferToThread(
-                    select.select, [self.server_socket], [], [], True)
+                    select.select, [self.server_socket], [], [], 0.5)
                 if ready_to_read:
-                    client_socket, address = yield threads.deferToThread(self.server_socket.accept)
+                    # We are sure that a connection is available, so we can call
+                    # accept() without deferring it to a thread
+                    client_socket, address = self.server_socket.accept()
                     key_data = get_public_key_data(self.key.fingerprint)
                     kd_decoded = key_data.decode('utf-8')
                     yield threads.deferToThread(client_socket.sendall, kd_decoded)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]