提交 5e62ba34 编写于 作者: R Royce Lv 提交者: Eric Blake

adding handling EINTR to poll to make it more robust

some system call and signal will interrupt poll,
making event loop stops and fails to react events and keepalive message
from libvirt.
adding handling EINTR to poll to make it more robust
Signed-off-by: NRoyce Lv <lvroyce@linux.vnet.ibm.com>
上级 5e21da56
...@@ -178,48 +178,53 @@ class virEventLoopPure: ...@@ -178,48 +178,53 @@ class virEventLoopPure:
def run_once(self): def run_once(self):
sleep = -1 sleep = -1
self.runningPoll = True self.runningPoll = True
next = self.next_timeout() try:
debug("Next timeout due at %d" % next) next = self.next_timeout()
if next > 0: debug("Next timeout due at %d" % next)
now = int(time.time() * 1000) if next > 0:
if now >= next: now = int(time.time() * 1000)
sleep = 0 if now >= next:
else: sleep = 0
sleep = (next - now) / 1000.0 else:
sleep = (next - now) / 1000.0
debug("Poll with a sleep of %d" % sleep)
events = self.poll.poll(sleep) debug("Poll with a sleep of %d" % sleep)
events = self.poll.poll(sleep)
# Dispatch any file handle events that occurred
for (fd, revents) in events: # Dispatch any file handle events that occurred
# See if the events was from the self-pipe for (fd, revents) in events:
# telling us to wakup. if so, then discard # See if the events was from the self-pipe
# the data just continue # telling us to wakup. if so, then discard
if fd == self.pipetrick[0]: # the data just continue
self.pendingWakeup = False if fd == self.pipetrick[0]:
data = os.read(fd, 1) self.pendingWakeup = False
continue data = os.read(fd, 1)
continue
h = self.get_handle_by_fd(fd)
if h: h = self.get_handle_by_fd(fd)
debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents)) if h:
h.dispatch(self.events_from_poll(revents)) debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents))
h.dispatch(self.events_from_poll(revents))
now = int(time.time() * 1000)
for t in self.timers:
interval = t.get_interval()
if interval < 0:
continue
want = t.get_last_fired() + interval now = int(time.time() * 1000)
# Deduct 20ms, since schedular timeslice for t in self.timers:
# means we could be ever so slightly early interval = t.get_interval()
if now >= (want-20): if interval < 0:
debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want))) continue
t.set_last_fired(now)
t.dispatch() want = t.get_last_fired() + interval
# Deduct 20ms, since scheduler timeslice
self.runningPoll = False # means we could be ever so slightly early
if now >= (want-20):
debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want)))
t.set_last_fired(now)
t.dispatch()
except (os.error, select.error), e:
if e.args[0] != errno.EINTR:
raise
finally:
self.runningPoll = False
# Actually the event loop forever # Actually the event loop forever
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册