From 8216580d1f06d8082ccd652ff873bee9200a6adb Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 15 Mar 2010 13:21:22 +0000 Subject: [PATCH] AsyncUDPSocket: abstract do_read function This basically implements read handling, without catching all exceptions. When using the socket in synchronous mode, it's useful to avoid losing exception data (which, in an async daemon, can only be logged) Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/daemon.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/daemon.py b/lib/daemon.py index e10f6e22c..6eca3a3ec 100644 --- a/lib/daemon.py +++ b/lib/daemon.py @@ -91,20 +91,23 @@ class AsyncUDPSocket(asyncore.dispatcher): # differ and treat all messages equally. pass + def do_read(self): + try: + payload, address = self.recvfrom(constants.MAX_UDP_DATA_SIZE) + except socket.error, err: + if err.errno == errno.EINTR: + # we got a signal while trying to read. no need to do anything, + # handle_read will be called again if there is data on the socket. + return + else: + raise + ip, port = address + self.handle_datagram(payload, ip, port) + # this method is overriding an asyncore.dispatcher method def handle_read(self): try: - try: - payload, address = self.recvfrom(constants.MAX_UDP_DATA_SIZE) - except socket.error, err: - if err.errno == errno.EINTR: - # we got a signal while trying to read. no need to do anything, - # handle_read will be called again if there is data on the socket. - return - else: - raise - ip, port = address - self.handle_datagram(payload, ip, port) + self.do_read() except: # pylint: disable-msg=W0702 # we need to catch any exception here, log it, but proceed, because even # if we failed handling a single request, we still want to continue. -- GitLab