# limitations under the License.
import errno
-import logging
import select
+import ovs.timeval
+import ovs.vlog
+
+vlog = ovs.vlog.Vlog("poller")
+
class Poller(object):
"""High-level wrapper around the "poll" system call.
be select.POLLIN or select.POLLOUT or their bitwise-OR). The following
call to self.block() will wake up when 'fd' becomes ready for one or
more of the requested events.
-
+
The event registration is one-shot: only the following call to
self.block() is affected. The event will need to be re-registered
after self.block() is called if it is to persist.
def timer_wait_until(self, msec):
"""Causes the following call to self.block() to wake up when the
- current time, as returned by Time.msec(), reaches 'msec' or later. If
- 'msec' is earlier than the current time, the following call to
- self.block() will not block at all.
+ current time, as returned by ovs.timeval.msec(), reaches 'msec' or
+ later. If 'msec' is earlier than the current time, the following call
+ to self.block() will not block at all.
The timer registration is one-shot: only the following call to
self.block() is affected. The timer will need to be re-registered
after self.block() is called if it is to persist."""
- now = Time.msec()
+ now = ovs.timeval.msec()
if msec <= now:
self.immediate_wake()
else:
# XXX rate-limit
error, msg = e
if error != errno.EINTR:
- logging.error("poll: %s" % e[1])
+ vlog.err("poll: %s" % e[1])
finally:
self.__reset()
def __log_wakeup(self, events):
if not events:
- logging.debug("%d-ms timeout" % self.timeout)
+ vlog.dbg("%d-ms timeout" % self.timeout)
else:
for fd, revents in events:
if revents != 0:
s += "[POLLHUP]"
if revents & select.POLLNVAL:
s += "[POLLNVAL]"
- logging.debug("%s on fd %d" % (s, fd))
+ vlog.dbg("%s on fd %d" % (s, fd))
def __reset(self):
self.poll = select.poll()
- self.timeout = -1
-
+ self.timeout = -1