Patchwork [2,of,8] commandserver: extract handler of new socket connection

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

Comments

Yuya Nishihara - Dec. 6, 2018, 12:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540990958 -32400
#      Wed Oct 31 22:02:38 2018 +0900
# Node ID c9533007e0e09fe8129b46208dbb760ff8799a88
# Parent  958a93f4f9210c4b5669e4424f8d73b048ef72ed
commandserver: extract handler of new socket connection

This prepares for adding an IPC socket.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -565,11 +565,17 @@  class unixforkingservice(object):
                 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 @@  class unixforkingservice(object):
             else:
                 try:
                     selector.close()
-                    self._sock.close()
+                    sock.close()
                     self._runworker(conn)
                     conn.close()
                     os._exit(0)
@@ -593,7 +599,6 @@  class unixforkingservice(object):
                         self.ui.traceback(force=True)
                     finally:
                         os._exit(255)
-        selector.close()
 
     def _sigchldhandler(self, signal, frame):
         self._reapworkers(os.WNOHANG)