From 6ddf5c8f08128cf3fbd94354c85a87f06ec7a8cd Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 15 Mar 2010 11:43:21 +0000 Subject: [PATCH] AsyncUDPSocket.process_next_packet This function allows receiving socket data synchronously. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/daemon.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/daemon.py b/lib/daemon.py index 6eca3a3ec..0fba74db9 100644 --- a/lib/daemon.py +++ b/lib/daemon.py @@ -30,6 +30,7 @@ import logging import sched import time import socket +import select import sys from ganeti import utils @@ -156,6 +157,21 @@ class AsyncUDPSocket(asyncore.dispatcher): constants.MAX_UDP_DATA_SIZE)) self._out_queue.append((ip, port, payload)) + def process_next_packet(self, timeout=0): + """Process the next datagram, waiting for it if necessary. + + @type timeout: float + @param timeout: how long to wait for data + @rtype: boolean + @return: True if some data has been handled, False otherwise + + """ + if utils.WaitForFdCondition(self, select.POLLIN, timeout) & select.POLLIN: + self.do_read() + return True + else: + return False + class Mainloop(object): """Generic mainloop for daemons -- GitLab