Ticket #4350: sshpp.patch

File sshpp.patch, 2.4 KB (added by bshi, 8 years ago)
  • twisted/conch/ssh/session.py

    diff --git twisted/conch/ssh/session.py twisted/conch/ssh/session.py
    index c50372c..e315c8f 100755
    class SSHSessionProcessProtocol(protocol.ProcessProtocol): 
    188188
    189189    def __init__(self, session):
    190190        self.session = session
     191        self.lostOutOrErrFlag = False
    191192
    192193    def connectionMade(self):
    193194        if self.session.buf:
    class SSHSessionProcessProtocol(protocol.ProcessProtocol): 
    200201    def errReceived(self, err):
    201202        self.session.writeExtended(connection.EXTENDED_DATA_STDERR, err)
    202203
    203     def inConnectionLost(self):
    204         self.session.conn.sendEOF(self.session)
     204    def outConnectionLost(self):
     205        """
     206        EOF should only be sent when both STDOUT and STDERR have been closed.
     207        """
     208        if self.lostOutOrErrFlag is True:
     209            self.session.conn.sendEOF(self.session)
     210        else:
     211            self.lostOutOrErrFlag = True
     212
     213    def errConnectionLost(self):
     214        """
     215        See outConnectionLost().
     216        """
     217        self.outConnectionLost()
    205218
    206219    def connectionLost(self, reason = None):
    207220        self.session.loseConnection()
  • twisted/conch/test/test_session.py

    diff --git twisted/conch/test/test_session.py twisted/conch/test/test_session.py
    index f59fd72..e901913 100644
    class SSHSessionProcessProtocolTestCase(unittest.TestCase): 
    11131113                [(1, 'test data')])
    11141114
    11151115
    1116     def test_inConnectionLost(self):
     1116    def test_outConnectionLost(self):
    11171117        """
    1118         When inConnectionLost is called, it should send an EOF message,
     1118        When outConnectionLost and errConnectionLost are both called, we should
     1119        send an EOF message.
    11191120        """
    1120         self.pp.inConnectionLost()
     1121        self.pp.outConnectionLost()
     1122        self.assertFalse(self.session in self.session.conn.eofs)
     1123        self.pp.errConnectionLost()
     1124        self.assertTrue(self.session.conn.eofs[self.session])
     1125
     1126
     1127    def test_errConnectionLost(self):
     1128        """
     1129        Make sure reverse ordering of events in test_outConnectionLost also
     1130        sends EOF.
     1131        """
     1132        self.pp.errConnectionLost()
     1133        self.assertFalse(self.session in self.session.conn.eofs)
     1134        self.pp.outConnectionLost()
    11211135        self.assertTrue(self.session.conn.eofs[self.session])
    11221136
    11231137