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

AsyncUDPSocket.process_next_packet


This function allows receiving socket data synchronously.

Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent dfdc4060
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ import logging ...@@ -30,6 +30,7 @@ import logging
import sched import sched
import time import time
import socket import socket
import select
import sys import sys
from ganeti import utils from ganeti import utils
...@@ -156,6 +157,21 @@ class AsyncUDPSocket(asyncore.dispatcher): ...@@ -156,6 +157,21 @@ class AsyncUDPSocket(asyncore.dispatcher):
constants.MAX_UDP_DATA_SIZE)) constants.MAX_UDP_DATA_SIZE))
self._out_queue.append((ip, port, payload)) 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): class Mainloop(object):
"""Generic mainloop for daemons """Generic mainloop for daemons
......
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