Mercurial > hg
comparison mercurial/commandserver.py @ 29548:9da1adc18639
commandserver: drop old unixservice implementation
It's been superseded by unixforkingservice.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 22 May 2016 13:45:09 +0900 |
parents | 024e8f82f3de |
children | ee8186457516 |
comparison
equal
deleted
inserted
replaced
29547:300318b7d66d | 29548:9da1adc18639 |
---|---|
22 from . import ( | 22 from . import ( |
23 encoding, | 23 encoding, |
24 error, | 24 error, |
25 util, | 25 util, |
26 ) | 26 ) |
27 | |
28 socketserver = util.socketserver | |
29 | 27 |
30 logfile = None | 28 logfile = None |
31 | 29 |
32 def log(*args): | 30 def log(*args): |
33 if not logfile: | 31 if not logfile: |
421 def createcmdserver(self, repo, conn, fin, fout): | 419 def createcmdserver(self, repo, conn, fin, fout): |
422 """Create new command server instance; called in the process that | 420 """Create new command server instance; called in the process that |
423 serves for the current connection""" | 421 serves for the current connection""" |
424 return server(self.ui, repo, fin, fout) | 422 return server(self.ui, repo, fin, fout) |
425 | 423 |
426 class _requesthandler(socketserver.BaseRequestHandler): | 424 class unixforkingservice(object): |
427 def handle(self): | |
428 _serverequest(self.server.ui, self.server.repo, self.request, | |
429 self._createcmdserver) | |
430 | |
431 def _createcmdserver(self, repo, conn, fin, fout): | |
432 ui = self.server.ui | |
433 return server(ui, repo, fin, fout) | |
434 | |
435 class unixservice(object): | |
436 """ | 425 """ |
437 Listens on unix domain socket and forks server per connection | 426 Listens on unix domain socket and forks server per connection |
438 """ | 427 """ |
439 def __init__(self, ui, repo, opts): | 428 |
429 def __init__(self, ui, repo, opts, handler=None): | |
440 self.ui = ui | 430 self.ui = ui |
441 self.repo = repo | 431 self.repo = repo |
442 self.address = opts['address'] | 432 self.address = opts['address'] |
443 if not util.safehasattr(socketserver, 'UnixStreamServer'): | 433 if not util.safehasattr(socket, 'AF_UNIX'): |
444 raise error.Abort(_('unsupported platform')) | 434 raise error.Abort(_('unsupported platform')) |
445 if not self.address: | 435 if not self.address: |
446 raise error.Abort(_('no socket path specified with --address')) | 436 raise error.Abort(_('no socket path specified with --address')) |
447 | |
448 def init(self): | |
449 class cls(socketserver.ForkingMixIn, socketserver.UnixStreamServer): | |
450 ui = self.ui | |
451 repo = self.repo | |
452 self.server = cls(self.address, _requesthandler) | |
453 self.ui.status(_('listening at %s\n') % self.address) | |
454 self.ui.flush() # avoid buffering of status message | |
455 | |
456 def _cleanup(self): | |
457 os.unlink(self.address) | |
458 | |
459 def run(self): | |
460 try: | |
461 self.server.serve_forever() | |
462 finally: | |
463 self._cleanup() | |
464 | |
465 class unixforkingservice(unixservice): | |
466 def __init__(self, ui, repo, opts, handler=None): | |
467 super(unixforkingservice, self).__init__(ui, repo, opts) | |
468 self._servicehandler = handler or unixservicehandler(ui) | 437 self._servicehandler = handler or unixservicehandler(ui) |
469 self._sock = None | 438 self._sock = None |
470 self._oldsigchldhandler = None | 439 self._oldsigchldhandler = None |
471 self._workerpids = set() # updated by signal handler; do not iterate | 440 self._workerpids = set() # updated by signal handler; do not iterate |
472 | 441 |