mercurial/wireprotoserver.py
changeset 36523 e7411fb7ba7f
parent 36372 b8d0761a85c7
child 36526 7cc4a9b9732a
equal deleted inserted replaced
36522:c3df20906689 36523:e7411fb7ba7f
     7 from __future__ import absolute_import
     7 from __future__ import absolute_import
     8 
     8 
     9 import contextlib
     9 import contextlib
    10 import struct
    10 import struct
    11 import sys
    11 import sys
       
    12 import threading
    12 
    13 
    13 from .i18n import _
    14 from .i18n import _
    14 from . import (
    15 from . import (
    15     encoding,
    16     encoding,
    16     error,
    17     error,
   371         return 'remote:ssh:' + client
   372         return 'remote:ssh:' + client
   372 
   373 
   373 class sshv2protocolhandler(sshv1protocolhandler):
   374 class sshv2protocolhandler(sshv1protocolhandler):
   374     """Protocol handler for version 2 of the SSH protocol."""
   375     """Protocol handler for version 2 of the SSH protocol."""
   375 
   376 
   376 def _runsshserver(ui, repo, fin, fout):
   377 def _runsshserver(ui, repo, fin, fout, ev):
   377     # This function operates like a state machine of sorts. The following
   378     # This function operates like a state machine of sorts. The following
   378     # states are defined:
   379     # states are defined:
   379     #
   380     #
   380     # protov1-serving
   381     # protov1-serving
   381     #    Server is in protocol version 1 serving mode. Commands arrive on
   382     #    Server is in protocol version 1 serving mode. Commands arrive on
   428 
   429 
   429     state = 'protov1-serving'
   430     state = 'protov1-serving'
   430     proto = sshv1protocolhandler(ui, fin, fout)
   431     proto = sshv1protocolhandler(ui, fin, fout)
   431     protoswitched = False
   432     protoswitched = False
   432 
   433 
   433     while True:
   434     while not ev.is_set():
   434         if state == 'protov1-serving':
   435         if state == 'protov1-serving':
   435             # Commands are issued on new lines.
   436             # Commands are issued on new lines.
   436             request = fin.readline()[:-1]
   437             request = fin.readline()[:-1]
   437 
   438 
   438             # Empty lines signal to terminate the connection.
   439             # Empty lines signal to terminate the connection.
   599         # Prevent insertion/deletion of CRs
   600         # Prevent insertion/deletion of CRs
   600         util.setbinary(self._fin)
   601         util.setbinary(self._fin)
   601         util.setbinary(self._fout)
   602         util.setbinary(self._fout)
   602 
   603 
   603     def serve_forever(self):
   604     def serve_forever(self):
   604         _runsshserver(self._ui, self._repo, self._fin, self._fout)
   605         self.serveuntil(threading.Event())
   605         sys.exit(0)
   606         sys.exit(0)
       
   607 
       
   608     def serveuntil(self, ev):
       
   609         """Serve until a threading.Event is set."""
       
   610         _runsshserver(self._ui, self._repo, self._fin, self._fout, ev)