commandserver: extract handler of new socket connection
authorYuya Nishihara <yuya@tcha.org>
Wed, 31 Oct 2018 22:02:38 +0900
changeset 40876 dc9901558e3c
parent 40875 e7110f44ee2d
child 40877 9f00de4dc7cb
commandserver: extract handler of new socket connection This prepares for adding an IPC socket.
mercurial/commandserver.py
--- a/mercurial/commandserver.py	Wed Oct 31 21:57:11 2018 +0900
+++ b/mercurial/commandserver.py	Wed Oct 31 22:02:38 2018 +0900
@@ -565,11 +565,17 @@
                 if exiting:
                     break
                 continue
+            self._acceptnewconnection(self._sock, selector)
+        selector.close()
+
+    def _acceptnewconnection(self, sock, selector):
+        h = self._servicehandler
+        if True:
             try:
-                conn, _addr = self._sock.accept()
+                conn, _addr = sock.accept()
             except socket.error as inst:
                 if inst.args[0] == errno.EINTR:
-                    continue
+                    return
                 raise
 
             pid = os.fork()
@@ -584,7 +590,7 @@
             else:
                 try:
                     selector.close()
-                    self._sock.close()
+                    sock.close()
                     self._runworker(conn)
                     conn.close()
                     os._exit(0)
@@ -593,7 +599,6 @@
                         self.ui.traceback(force=True)
                     finally:
                         os._exit(255)
-        selector.close()
 
     def _sigchldhandler(self, signal, frame):
         self._reapworkers(os.WNOHANG)