Patchwork [4,of,8] commandserver: loop over selector events

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 6, 2018, 12:45 p.m.
Message ID <af9746ae6d6245778885.1544100311@mimosa>
Download mbox | patch
Permalink /patch/37026/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 6, 2018, 12:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540991145 -32400
#      Wed Oct 31 22:05:45 2018 +0900
# Node ID af9746ae6d62457788853eda54374b192b7a7134
# Parent  92023422fbe3cf05e6d25b8213bd1e5a749c8e98
commandserver: loop over selector events

An IPC socket will be waited by the same selector.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -541,7 +541,8 @@  class unixforkingservice(object):
         exiting = False
         h = self._servicehandler
         selector = selectors.DefaultSelector()
-        selector.register(self._sock, selectors.EVENT_READ)
+        selector.register(self._sock, selectors.EVENT_READ,
+                          self._acceptnewconnection)
         while True:
             if not exiting and h.shouldexit():
                 # clients can no longer connect() to the domain socket, so
@@ -552,20 +553,21 @@  class unixforkingservice(object):
                 self._unlinksocket()
                 exiting = True
             try:
-                ready = selector.select(timeout=h.pollinterval)
+                events = selector.select(timeout=h.pollinterval)
             except OSError as inst:
                 # selectors2 raises ETIMEDOUT if timeout exceeded while
                 # handling signal interrupt. That's probably wrong, but
                 # we can easily get around it.
                 if inst.errno != errno.ETIMEDOUT:
                     raise
-                ready = []
-            if not ready:
+                events = []
+            if not events:
                 # only exit if we completed all queued requests
                 if exiting:
                     break
                 continue
-            self._acceptnewconnection(self._sock, selector)
+            for key, _mask in events:
+                key.data(key.fileobj, selector)
         selector.close()
 
     def _acceptnewconnection(self, sock, selector):