commandserver: extract handler of new socket connection
authorYuya Nishihara <yuya@tcha.org>
Wed, 31 Oct 2018 22:02:38 +0900
changeset 53642 dc9901558e3c6a78bad3f6594b3888f95104c443
parent 53641 e7110f44ee2d0e14ce909ace35b39882dcc29f97
child 53643 9f00de4dc7cb995aae9245fb8b0044fd45e476ad
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
commandserver: extract handler of new socket connection This prepares for adding an IPC socket.
mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -560,45 +560,50 @@ class unixforkingservice(object):
                 if inst.errno != errno.ETIMEDOUT:
                     raise
                 ready = []
             if not ready:
                 # only exit if we completed all queued requests
                 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()
             if pid:
                 try:
                     self.ui.log(b'cmdserver',
                                 b'forked worker process (pid=%d)\n', pid)
                     self._workerpids.add(pid)
                     h.newconnection()
                 finally:
                     conn.close()  # release handle in parent process
             else:
                 try:
                     selector.close()
-                    self._sock.close()
+                    sock.close()
                     self._runworker(conn)
                     conn.close()
                     os._exit(0)
                 except:  # never return, hence no re-raises
                     try:
                         self.ui.traceback(force=True)
                     finally:
                         os._exit(255)
-        selector.close()
 
     def _sigchldhandler(self, signal, frame):
         self._reapworkers(os.WNOHANG)
 
     def _reapworkers(self, options):
         while self._workerpids:
             try:
                 pid, _status = os.waitpid(-1, options)