typeintandem / tandem

Typing in Tandem. Decentralized, cross-editor, collaborative text-editing!
Apache License 2.0
698 stars 20 forks source link

Use select() in the UDPGateway #106

Closed geoffxy closed 6 years ago

geoffxy commented 6 years ago

This lets us shutdown the server (and also the agent) cleanly.

As described on Slack, with recvfrom() it's not guaranteed for us to be unblocked when the socket is closed. It just happened that on macOS we got an exception when the socket was closed. On Linux, this wasn't the case and so the reader thread would be blocked indefinitely.

So the recommended approach is to use select(), which will block the thread until a timeout or until the socket is ready to be read (whichever occurs first). In practice this means we check the _shutdown_requested flag at least every SELECT_TIMEOUT seconds.

This also adds some __init__.py files and makes the server bind to all interfaces by default.

geoffxy commented 6 years ago

And yeah - agreed about the high level API in Python. I was working with select() in C as well for CS 454. It definitely was not fun 😞