tftpy icon indicating copy to clipboard operation
tftpy copied to clipboard

shouldn't use select() with blocking sockets

Open msoulier opened this issue 15 years ago • 3 comments

Currently we use a select loop and blocking sockets, which is actually not a good combination. There are many reasons why select can return, and sometimes they result in a blocking read() operation, which would block the entire server.

msoulier avatar May 11 '10 17:05 msoulier

Scheduling for 1.0.

msoulier avatar Aug 26 '11 12:08 msoulier

Sorry, but would this issue be resolved with this small change?

--- a/tftpy/TftpServer.py
+++ b/tftpy/TftpServer.py
@@ -71,9 +71,9 @@ class TftpServer(TftpSession):
         log.info("Server requested on ip %s, port %s"
                 % (listenip, listenport))
         try:
-            # FIXME - sockets should be non-blocking
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
             self.sock.bind((listenip, listenport))
+            self.sock.setblocking(0)
             _, self.listenport = self.sock.getsockname()
         except socket.error, err:
             # Reraise it for now.

sanseihappa avatar Dec 17 '15 18:12 sanseihappa

Setting the socket non-blocking would fix the select() problem but I'll need to ensure that we're reading from the socket properly in non-blocking mode.

msoulier avatar Mar 22 '19 14:03 msoulier