From be02586133921a7d9796f02c0203691a7dbff7d6 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 6 Sep 2022 12:23:52 +0200 Subject: [PATCH] Added detach handler to TCP Server Interface --- RNS/Interfaces/TCPInterface.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index bcf02ee..29f9ed9 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -417,6 +417,7 @@ class TCPServerInterface(Interface): self.IN = True self.OUT = False self.name = name + self.detached = False self.i2p_tunneled = i2p_tunneled self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL @@ -476,6 +477,21 @@ class TCPServerInterface(Interface): def processOutgoing(self, data): pass + + def detach(self): + if self.server != None: + if hasattr(self.server, "shutdown"): + if callable(self.server.shutdown): + try: + RNS.log("Detaching "+str(self), RNS.LOG_DEBUG) + self.server.shutdown() + self.detached = True + self.server = None + + except Exception as e: + RNS.log("Error while shutting down server for "+str(self)+": "+str(e)) + + def __str__(self): return "TCPServerInterface["+self.name+"/"+self.bind_ip+":"+str(self.bind_port)+"]"