From 66c4eebf55db7437063cfa1fe09ee5bca28fbe14 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Fri, 3 Mar 2017 23:43:05 -0500 Subject: [PATCH] add the close_socket() function requested in #107 --- py25/bacpypes/app.py | 12 ++++++++++++ py25/bacpypes/bvllservice.py | 8 ++++++++ py25/bacpypes/udp.py | 6 ++++++ py27/bacpypes/app.py | 12 ++++++++++++ py27/bacpypes/bvllservice.py | 8 ++++++++ py27/bacpypes/udp.py | 6 ++++++ py34/bacpypes/app.py | 12 ++++++++++++ py34/bacpypes/bvllservice.py | 8 ++++++++ py34/bacpypes/udp.py | 6 ++++++ 9 files changed, 78 insertions(+) diff --git a/py25/bacpypes/app.py b/py25/bacpypes/app.py index d98f2d4..2817331 100755 --- a/py25/bacpypes/app.py +++ b/py25/bacpypes/app.py @@ -503,6 +503,12 @@ class BIPSimpleApplication(ApplicationIOController, WhoIsIAmServices, ReadWriteP # bind the BIP stack to the network, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPSimpleApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + bacpypes_debugging(BIPSimpleApplication) # @@ -550,6 +556,12 @@ class BIPForeignApplication(ApplicationIOController, WhoIsIAmServices, ReadWrite # bind the NSAP to the stack, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPForeignApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + bacpypes_debugging(BIPForeignApplication) # diff --git a/py25/bacpypes/bvllservice.py b/py25/bacpypes/bvllservice.py index cd5ed40..5713976 100755 --- a/py25/bacpypes/bvllservice.py +++ b/py25/bacpypes/bvllservice.py @@ -102,6 +102,14 @@ class UDPMultiplexer: self.annexH = _MultiplexServer(self) self.annexJ = _MultiplexServer(self) + def close_socket(self): + if _debug: UDPMultiplexer._debug("close_socket") + + # pass along the close to the director(s) + self.directPort.close_socket() + if self.broadcastPort: + self.broadcastPort.close_socket() + def indication(self, server, pdu): if _debug: UDPMultiplexer._debug("indication %r %r", server, pdu) diff --git a/py25/bacpypes/udp.py b/py25/bacpypes/udp.py index 6659a51..b917ad8 100755 --- a/py25/bacpypes/udp.py +++ b/py25/bacpypes/udp.py @@ -248,6 +248,12 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint): # let the director handle the error self.handle_error(err) + def close_socket(self): + """Close the socket.""" + if _debug: UDPDirector._debug("close_socket") + + self.socket.close() + def handle_close(self): """Remove this from the monitor when it's closed.""" if _debug: UDPDirector._debug("handle_close") diff --git a/py27/bacpypes/app.py b/py27/bacpypes/app.py index fe974d6..805c0f6 100755 --- a/py27/bacpypes/app.py +++ b/py27/bacpypes/app.py @@ -500,6 +500,12 @@ class BIPSimpleApplication(ApplicationIOController, WhoIsIAmServices, ReadWriteP # bind the BIP stack to the network, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPSimpleApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + # # BIPForeignApplication # @@ -546,6 +552,12 @@ class BIPForeignApplication(ApplicationIOController, WhoIsIAmServices, ReadWrite # bind the NSAP to the stack, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPForeignApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + # # BIPNetworkApplication # diff --git a/py27/bacpypes/bvllservice.py b/py27/bacpypes/bvllservice.py index 9501695..8fc67fc 100755 --- a/py27/bacpypes/bvllservice.py +++ b/py27/bacpypes/bvllservice.py @@ -103,6 +103,14 @@ class UDPMultiplexer: self.annexH = _MultiplexServer(self) self.annexJ = _MultiplexServer(self) + def close_socket(self): + if _debug: UDPMultiplexer._debug("close_socket") + + # pass along the close to the director(s) + self.directPort.close_socket() + if self.broadcastPort: + self.broadcastPort.close_socket() + def indication(self, server, pdu): if _debug: UDPMultiplexer._debug("indication %r %r", server, pdu) diff --git a/py27/bacpypes/udp.py b/py27/bacpypes/udp.py index 8c71d8d..643c45b 100755 --- a/py27/bacpypes/udp.py +++ b/py27/bacpypes/udp.py @@ -247,6 +247,12 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint): # let the director handle the error self.handle_error(err) + def close_socket(self): + """Close the socket.""" + if _debug: UDPDirector._debug("close_socket") + + self.socket.close() + def handle_close(self): """Remove this from the monitor when it's closed.""" if _debug: UDPDirector._debug("handle_close") diff --git a/py34/bacpypes/app.py b/py34/bacpypes/app.py index fe974d6..805c0f6 100755 --- a/py34/bacpypes/app.py +++ b/py34/bacpypes/app.py @@ -500,6 +500,12 @@ class BIPSimpleApplication(ApplicationIOController, WhoIsIAmServices, ReadWriteP # bind the BIP stack to the network, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPSimpleApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + # # BIPForeignApplication # @@ -546,6 +552,12 @@ class BIPForeignApplication(ApplicationIOController, WhoIsIAmServices, ReadWrite # bind the NSAP to the stack, no network number self.nsap.bind(self.bip) + def close_socket(self): + if _debug: BIPForeignApplication._debug("close_socket") + + # pass to the multiplexer, then down to the sockets + self.mux.close_socket() + # # BIPNetworkApplication # diff --git a/py34/bacpypes/bvllservice.py b/py34/bacpypes/bvllservice.py index cdfee34..087b88d 100755 --- a/py34/bacpypes/bvllservice.py +++ b/py34/bacpypes/bvllservice.py @@ -102,6 +102,14 @@ class UDPMultiplexer: self.annexH = _MultiplexServer(self) self.annexJ = _MultiplexServer(self) + def close_socket(self): + if _debug: UDPMultiplexer._debug("close_socket") + + # pass along the close to the director(s) + self.directPort.close_socket() + if self.broadcastPort: + self.broadcastPort.close_socket() + def indication(self, server, pdu): if _debug: UDPMultiplexer._debug("indication %r %r", server, pdu) diff --git a/py34/bacpypes/udp.py b/py34/bacpypes/udp.py index 2966efb..d2c1063 100755 --- a/py34/bacpypes/udp.py +++ b/py34/bacpypes/udp.py @@ -247,6 +247,12 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint): # let the director handle the error self.handle_error(err) + def close_socket(self): + """Close the socket.""" + if _debug: UDPDirector._debug("close_socket") + + self.socket.close() + def handle_close(self): """Remove this from the monitor when it's closed.""" if _debug: UDPDirector._debug("handle_close")