Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commandserver.py @ 32276:c8b9943c07eb
commandserver: move "listen" responsibility from service to handler
This enables chg to replace a server socket in an atomic way:
1. bind to a temp address
2. listen
3. rename
Currently 3 happens before 2 so a client may see the socket file but fails
to connect to it.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 30 Apr 2017 11:08:27 -0700 |
parents | 48dea083f66d |
children | 1ada3d18e7fb |
comparison
equal
deleted
inserted
replaced
32275:cf415777a22c | 32276:c8b9943c07eb |
---|---|
407 def __init__(self, ui): | 407 def __init__(self, ui): |
408 self.ui = ui | 408 self.ui = ui |
409 | 409 |
410 def bindsocket(self, sock, address): | 410 def bindsocket(self, sock, address): |
411 util.bindunixsocket(sock, address) | 411 util.bindunixsocket(sock, address) |
412 sock.listen(socket.SOMAXCONN) | |
412 | 413 |
413 def unlinksocket(self, address): | 414 def unlinksocket(self, address): |
414 os.unlink(address) | 415 os.unlink(address) |
415 | 416 |
416 def printbanner(self, address): | 417 def printbanner(self, address): |
450 self._socketunlinked = None | 451 self._socketunlinked = None |
451 | 452 |
452 def init(self): | 453 def init(self): |
453 self._sock = socket.socket(socket.AF_UNIX) | 454 self._sock = socket.socket(socket.AF_UNIX) |
454 self._servicehandler.bindsocket(self._sock, self.address) | 455 self._servicehandler.bindsocket(self._sock, self.address) |
455 self._sock.listen(socket.SOMAXCONN) | |
456 o = signal.signal(signal.SIGCHLD, self._sigchldhandler) | 456 o = signal.signal(signal.SIGCHLD, self._sigchldhandler) |
457 self._oldsigchldhandler = o | 457 self._oldsigchldhandler = o |
458 self._servicehandler.printbanner(self.address) | 458 self._servicehandler.printbanner(self.address) |
459 self._socketunlinked = False | 459 self._socketunlinked = False |
460 | 460 |