[PATCH 4 of 8] commandserver: loop over selector events

Yuya Nishihara yuya at tcha.org
Thu Dec 6 07:45:11 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at 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.

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):


More information about the Mercurial-devel mailing list