commandserver: loop over selector events
authorYuya Nishihara <yuya@tcha.org>
Wed, 31 Oct 2018 22:05:45 +0900
changeset 53644 2525faf4ecdbe7418b47ea87fce24cb52e657308
parent 53643 9f00de4dc7cb995aae9245fb8b0044fd45e476ad
child 53645 0c638ff69f5c10bddf1b795c08dc5a6dd4f3ad66
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
commandserver: loop over selector events An IPC socket will be waited by the same selector.
mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -536,41 +536,43 @@ class unixforkingservice(object):
             self._mainloop()
         finally:
             self._cleanup()
 
     def _mainloop(self):
         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
                 # we stop queuing new requests.
                 # for requests that are queued (connect()-ed, but haven't been
                 # accept()-ed), handle them before exit. otherwise, clients
                 # waiting for recv() will receive ECONNRESET.
                 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):
         h = self._servicehandler
         try:
             conn, _addr = sock.accept()
         except socket.error as inst:
             if inst.args[0] == errno.EINTR: