[rtems-tools commit] tester/tftpd: Set the socket option to reuse.

Chris Johns chrisj at rtems.org
Tue Nov 27 02:55:44 UTC 2018


Module:    rtems-tools
Branch:    master
Commit:    bf5fdab115d8dc583548f6c270353fdb6d01c3a0
Changeset: http://git.rtems.org/rtems-tools/commit/?id=bf5fdab115d8dc583548f6c270353fdb6d01c3a0

Author:    Chris Johns <chrisj at rtems.org>
Date:      Tue Nov 27 11:24:38 2018 +1100

tester/tftpd: Set the socket option to reuse.

---

 tester/rt/tftpy/TftpServer.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tester/rt/tftpy/TftpServer.py b/tester/rt/tftpy/TftpServer.py
index 95ca70e..8dc6d78 100644
--- a/tester/rt/tftpy/TftpServer.py
+++ b/tester/rt/tftpy/TftpServer.py
@@ -76,6 +76,13 @@ class TftpServer(TftpSession):
         else:
             raise TftpException("The tftproot does not exist.")
 
+    def __del__(self):
+        if self.sock is not None:
+            try:
+                self.sock.close()
+            except:
+                pass
+
     def listen(self, listenip="", listenport=DEF_TFTP_PORT,
                timeout=SOCK_TIMEOUT):
         """Start a server listening on the supplied interface and port. This
@@ -90,6 +97,7 @@ class TftpServer(TftpSession):
         try:
             # FIXME - sockets should be non-blocking
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
             self.sock.bind((listenip, listenport))
             _, self.listenport = self.sock.getsockname()
         except socket.error as err:




More information about the vc mailing list