Skip to content
Snippets Groups Projects
Commit 8216580d authored by Guido Trotter's avatar Guido Trotter
Browse files

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent be0636e3
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment