mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
define handle_error function to match TCP api
This commit is contained in:
parent
1864cc5422
commit
a6f197cf03
|
@ -43,7 +43,7 @@ class UDPActor:
|
|||
# add a timer
|
||||
self.timeout = director.timeout
|
||||
if self.timeout > 0:
|
||||
self.timer = FunctionTask(self.IdleTimeout)
|
||||
self.timer = FunctionTask(self.idle_timeout)
|
||||
self.timer.install_task(_time() + self.timeout)
|
||||
else:
|
||||
self.timer = None
|
||||
|
@ -51,8 +51,8 @@ class UDPActor:
|
|||
# tell the director this is a new actor
|
||||
self.director.add_actor(self)
|
||||
|
||||
def IdleTimeout(self):
|
||||
if _debug: UDPActor._debug("IdleTimeout")
|
||||
def idle_timeout(self):
|
||||
if _debug: UDPActor._debug("idle_timeout")
|
||||
|
||||
# tell the director this is gone
|
||||
self.director.remove_actor(self)
|
||||
|
@ -77,6 +77,13 @@ class UDPActor:
|
|||
# process this as a response from the director
|
||||
self.director.response(pdu)
|
||||
|
||||
def handle_error(self, error=None):
|
||||
if _debug: UDPActor._debug("handle_error %r", error)
|
||||
|
||||
# pass along to the director
|
||||
if error is not None:
|
||||
self.director.actor_error(self, error)
|
||||
|
||||
bacpypes_debugging(UDPActor)
|
||||
|
||||
#
|
||||
|
@ -193,31 +200,31 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
return self.peers.get(address, None)
|
||||
|
||||
def handle_connect(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_connect")
|
||||
if _debug: UDPDirector._debug("handle_connect")
|
||||
|
||||
def readable(self):
|
||||
return 1
|
||||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_read")
|
||||
if _debug: UDPDirector._debug("handle_read")
|
||||
|
||||
try:
|
||||
msg, addr = self.socket.recvfrom(65536)
|
||||
if _debug: deferred(UDPDirector._debug, " - received %d octets from %s", len(msg), addr)
|
||||
if _debug: UDPDirector._debug(" - received %d octets from %s", len(msg), addr)
|
||||
|
||||
# send the PDU up to the client
|
||||
deferred(self._response, PDU(msg, source=addr))
|
||||
|
||||
except socket.timeout, err:
|
||||
deferred(UDPDirector._error, "handle_read socket timeout: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket timeout: %s", err)
|
||||
|
||||
except IOError as err:
|
||||
except socket.error, err:
|
||||
if err.args[0] == 11:
|
||||
pass
|
||||
else:
|
||||
deferred(UDPDirector._error, "handle_read socket error: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
# let the director handle the error
|
||||
self.handle_error(err)
|
||||
|
||||
def writable(self):
|
||||
|
@ -226,23 +233,29 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
|
||||
def handle_write(self):
|
||||
"""get a PDU from the queue and send it."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_write")
|
||||
if _debug: UDPDirector._debug("handle_write")
|
||||
|
||||
try:
|
||||
pdu = self.request.get()
|
||||
|
||||
sent = self.socket.sendto(pdu.pduData, pdu.pduDestination)
|
||||
if _debug: deferred(UDPDirector._debug, " - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
if _debug: UDPDirector._debug(" - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
|
||||
except IOError as err:
|
||||
deferred(UDPDirector._error, "handle_write socket error: %s", err)
|
||||
except socket.error, err:
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
self.handle_error(err)
|
||||
# get the peer
|
||||
peer = self.peers.get(pdu.pduDestination, None)
|
||||
if peer:
|
||||
# let the actor handle the error
|
||||
peer.handle_error(err)
|
||||
else:
|
||||
# let the director handle the error
|
||||
self.handle_error(err)
|
||||
|
||||
def handle_close(self):
|
||||
"""Remove this from the monitor when it's closed."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_close")
|
||||
if _debug: UDPDirector._debug("handle_close")
|
||||
|
||||
self.close()
|
||||
self.socket = None
|
||||
|
|
|
@ -44,7 +44,7 @@ class UDPActor:
|
|||
# add a timer
|
||||
self.timeout = director.timeout
|
||||
if self.timeout > 0:
|
||||
self.timer = FunctionTask(self.IdleTimeout)
|
||||
self.timer = FunctionTask(self.idle_timeout)
|
||||
self.timer.install_task(_time() + self.timeout)
|
||||
else:
|
||||
self.timer = None
|
||||
|
@ -52,8 +52,8 @@ class UDPActor:
|
|||
# tell the director this is a new actor
|
||||
self.director.add_actor(self)
|
||||
|
||||
def IdleTimeout(self):
|
||||
if _debug: UDPActor._debug("IdleTimeout")
|
||||
def idle_timeout(self):
|
||||
if _debug: UDPActor._debug("idle_timeout")
|
||||
|
||||
# tell the director this is gone
|
||||
self.director.remove_actor(self)
|
||||
|
@ -78,6 +78,13 @@ class UDPActor:
|
|||
# process this as a response from the director
|
||||
self.director.response(pdu)
|
||||
|
||||
def handle_error(self, error=None):
|
||||
if _debug: UDPActor._debug("handle_error %r", error)
|
||||
|
||||
# pass along to the director
|
||||
if error is not None:
|
||||
self.director.actor_error(self, error)
|
||||
|
||||
#
|
||||
# UDPPickleActor
|
||||
#
|
||||
|
@ -192,29 +199,29 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
return self.peers.get(address, None)
|
||||
|
||||
def handle_connect(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_connect")
|
||||
if _debug: UDPDirector._debug("handle_connect")
|
||||
|
||||
def readable(self):
|
||||
return 1
|
||||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_read")
|
||||
if _debug: UDPDirector._debug("handle_read")
|
||||
|
||||
try:
|
||||
msg, addr = self.socket.recvfrom(65536)
|
||||
if _debug: deferred(UDPDirector._debug, " - received %d octets from %s", len(msg), addr)
|
||||
if _debug: UDPDirector._debug(" - received %d octets from %s", len(msg), addr)
|
||||
|
||||
# send the PDU up to the client
|
||||
deferred(self._response, PDU(msg, source=addr))
|
||||
|
||||
except socket.timeout as err:
|
||||
deferred(UDPDirector._error, "handle_read socket timeout: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket timeout: %s", err)
|
||||
|
||||
except IOError as err:
|
||||
except socket.error as err:
|
||||
if err.args[0] == 11:
|
||||
pass
|
||||
else:
|
||||
deferred(UDPDirector._error, "handle_read socket error: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
self.handle_error(err)
|
||||
|
@ -225,23 +232,29 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
|
||||
def handle_write(self):
|
||||
"""get a PDU from the queue and send it."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_write")
|
||||
if _debug: UDPDirector._debug("handle_write")
|
||||
|
||||
try:
|
||||
pdu = self.request.get()
|
||||
|
||||
sent = self.socket.sendto(pdu.pduData, pdu.pduDestination)
|
||||
if _debug: deferred(UDPDirector._debug, " - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
if _debug: UDPDirector._debug(" - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
|
||||
except IOError as err:
|
||||
deferred(UDPDirector._error, "handle_write socket error: %s", err)
|
||||
except socket.error as err:
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
self.handle_error(err)
|
||||
# get the peer
|
||||
peer = self.peers.get(pdu.pduDestination, None)
|
||||
if peer:
|
||||
# let the actor handle the error
|
||||
peer.handle_error(err)
|
||||
else:
|
||||
# let the director handle the error
|
||||
self.handle_error(err)
|
||||
|
||||
def handle_close(self):
|
||||
"""Remove this from the monitor when it's closed."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_close")
|
||||
if _debug: UDPDirector._debug("handle_close")
|
||||
|
||||
self.close()
|
||||
self.socket = None
|
||||
|
|
|
@ -44,7 +44,7 @@ class UDPActor:
|
|||
# add a timer
|
||||
self.timeout = director.timeout
|
||||
if self.timeout > 0:
|
||||
self.timer = FunctionTask(self.IdleTimeout)
|
||||
self.timer = FunctionTask(self.idle_timeout)
|
||||
self.timer.install_task(_time() + self.timeout)
|
||||
else:
|
||||
self.timer = None
|
||||
|
@ -52,8 +52,8 @@ class UDPActor:
|
|||
# tell the director this is a new actor
|
||||
self.director.add_actor(self)
|
||||
|
||||
def IdleTimeout(self):
|
||||
if _debug: UDPActor._debug("IdleTimeout")
|
||||
def idle_timeout(self):
|
||||
if _debug: UDPActor._debug("idle_timeout")
|
||||
|
||||
# tell the director this is gone
|
||||
self.director.remove_actor(self)
|
||||
|
@ -78,6 +78,13 @@ class UDPActor:
|
|||
# process this as a response from the director
|
||||
self.director.response(pdu)
|
||||
|
||||
def handle_error(self, error=None):
|
||||
if _debug: UDPActor._debug("handle_error %r", error)
|
||||
|
||||
# pass along to the director
|
||||
if error is not None:
|
||||
self.director.actor_error(self, error)
|
||||
|
||||
#
|
||||
# UDPPickleActor
|
||||
#
|
||||
|
@ -192,29 +199,29 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
return self.peers.get(address, None)
|
||||
|
||||
def handle_connect(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_connect")
|
||||
if _debug: UDPDirector._debug("handle_connect")
|
||||
|
||||
def readable(self):
|
||||
return 1
|
||||
|
||||
def handle_read(self):
|
||||
if _debug: deferred(UDPDirector._debug, "handle_read")
|
||||
if _debug: UDPDirector._debug("handle_read")
|
||||
|
||||
try:
|
||||
msg, addr = self.socket.recvfrom(65536)
|
||||
if _debug: deferred(UDPDirector._debug, " - received %d octets from %s", len(msg), addr)
|
||||
if _debug: UDPDirector._debug(" - received %d octets from %s", len(msg), addr)
|
||||
|
||||
# send the PDU up to the client
|
||||
deferred(self._response, PDU(msg, source=addr))
|
||||
|
||||
except socket.timeout as err:
|
||||
deferred(UDPDirector._error, "handle_read socket timeout: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket timeout: %s", err)
|
||||
|
||||
except IOError as err:
|
||||
except socket.error as err:
|
||||
if err.args[0] == 11:
|
||||
pass
|
||||
else:
|
||||
deferred(UDPDirector._error, "handle_read socket error: %s", err)
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
self.handle_error(err)
|
||||
|
@ -225,29 +232,34 @@ class UDPDirector(asyncore.dispatcher, Server, ServiceAccessPoint):
|
|||
|
||||
def handle_write(self):
|
||||
"""get a PDU from the queue and send it."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_write")
|
||||
if _debug: UDPDirector._debug("handle_write")
|
||||
|
||||
try:
|
||||
pdu = self.request.get()
|
||||
|
||||
sent = self.socket.sendto(pdu.pduData, pdu.pduDestination)
|
||||
if _debug: deferred(UDPDirector._debug, " - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
if _debug: UDPDirector._debug(" - sent %d octets to %s", sent, pdu.pduDestination)
|
||||
|
||||
except IOError as err:
|
||||
deferred(UDPDirector._error, "handle_write socket error: %s", err)
|
||||
except socket.error as err:
|
||||
if _debug: UDPDirector._debug(" - socket error: %s", err)
|
||||
|
||||
# pass along to a handler
|
||||
self.handle_error(err)
|
||||
# get the peer
|
||||
peer = self.peers.get(pdu.pduDestination, None)
|
||||
if peer:
|
||||
# let the actor handle the error
|
||||
peer.handle_error(err)
|
||||
else:
|
||||
# let the director handle the error
|
||||
self.handle_error(err)
|
||||
|
||||
def handle_close(self):
|
||||
"""Remove this from the monitor when it's closed."""
|
||||
if _debug: deferred(UDPDirector._debug, "handle_close")
|
||||
if _debug: UDPDirector._debug("handle_close")
|
||||
|
||||
self.close()
|
||||
self.socket = None
|
||||
|
||||
def handle_error(self, error=None):
|
||||
"""Handle an error..."""
|
||||
if _debug: UDPDirector._debug("handle_error %r", error)
|
||||
|
||||
def indication(self, pdu):
|
||||
|
|
Loading…
Reference in New Issue
Block a user