Ticket #5150: halfclose.diff

File halfclose.diff, 2.4 KB (added by Itamar Turner-Trauring, 11 years ago)

Patch against #5118 branch (or trunk, if merged)

  • twisted/protocols/tls.py

     
    5151from twisted.internet.interfaces import ISystemHandle, ISSLTransport
    5252from twisted.internet.main import CONNECTION_DONE, CONNECTION_LOST
    5353from twisted.internet.protocol import Protocol
    54 from twisted.internet.interfaces import ITCPTransport
     54from twisted.internet.interfaces import ITCPTransport, IHalfCloseableProtocol
    5555from twisted.protocols.policies import ProtocolWrapper, WrappingFactory
    5656
    5757
     
    9797        be used as the reason passed to the application protocol's
    9898        C{connectionLost} method.
    9999    """
    100     implements(ISystemHandle, ISSLTransport)
     100    implements(ISystemHandle, ISSLTransport, IHalfCloseableProtocol)
    101101
    102102    _reason = None
    103103    _handshakeDone = False
     
    250250        self._flushReceiveBIO()
    251251
    252252
     253    def readConnectionLost(self, *reason):
     254        print self.factory._isClient, "Read connection lost"
     255        if not self._shuttingDown:
     256            self.transport.loseConnection() # just close uncleanly
     257
     258    def writeConnectionLost(self, *reason):
     259        print self.factory._isClient, "Write connection lost"
     260
     261
     262    _shuttingDown = False
     263
    253264    def _shutdownTLS(self):
    254265        """
    255266        Initiate, or reply to, the shutdown handshake of the TLS layer.
    256267        """
     268        self._shuttingDown = True
    257269        if (not self._lostConnection and
    258270            ITCPTransport.providedBy(self.transport)):
    259271            # In order for TLS shutdown notification to arrive as fast as
    260272            # possible, disable Nagle algorithm:
    261             self.transport.setTcpNoDelay(True)
     273            pass #self.transport.setTcpNoDelay(True)
    262274        shutdownSuccess = self._tlsConnection.shutdown()
    263275        self._flushSendBIO()
    264276        if shutdownSuccess:
     
    267279            # negotiation at all yet, in which case shutdown succeeds
    268280            # immediately.
    269281            self.transport.loseConnection()
     282        else:
     283            # We no longer expect to read anything, so close writing side of
     284            # our connection. This speeds up closing the underlying connection
     285            # once the TLS shutdown handshake is done:
     286            self.transport.loseWriteConnection()
    270287
    271288
    272289    def _tlsShutdownFinished(self, reason):