View Single Post
Old 12-03-2014, 08:04 AM   #8
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,486
Karma: 8025704
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
My point was that since the socket connection is accepted asynchronously, it would still be possible for a misbehaving device to block it, since, the connection could be accepted just before the misbehaving device is polled on the separate device thread, regardless of the order of devices in possibly_connected.
This is true.
Quote:
Without looking at the wireless driver code, I'm guessing that the reason it waits for a fixed time, is that it doesn't know if there is a currently connected device in the device thread? My inclination would be to add some API to the device driver interface so that the device thread can notify any drivers that it is already connected and therefore, they should abort any connection attempts. Then the connection thread can simply wait forever, until either the device subsytem informs it that it is connected, or actually tries to connect.
First, it turns out that it is trivial to change the driver to manage presence itself (MANAGES_DEVICE_PRESENCE = True).

To be sure I understand: you are suggesting that device.py (somehow) notify *all* device drivers when *any* device connects and disconnects. Given this notification, when the wireless device driver sub-thread accepts a connection, it checks the "already connected" state and waves off the connecting device if true. It would continue to check this state periodically and notify the connecting device if the state changes, with no limit on the number of checks. Of course it would do the right thing if the connecting device is itself.

The new API would look something like
def device_connected(self, device)
and
def device_disconnected(self, device)

The above is straightforward to implement. I will give it a try.
chaley is offline   Reply With Quote