def connectionLost(self, reason):
     """
     Fail the waiting Deferred, initialized by C{waitForDescriptor}, if there
     is one.
     """
     ConnectableProtocol.connectionLost(self, reason)
     if self.waiting is not None:
         self.waiting.errback(reason)
         self.waiting = None
     self.reason = reason
Example #2
0
 def connectionLost(self, reason):
     """
     Fail the waiting Deferred, initialized by C{waitForDescriptor}, if there
     is one.
     """
     ConnectableProtocol.connectionLost(self, reason)
     if self.waiting is not None:
         self.waiting.errback(reason)
         self.waiting = None
     self.reason = reason
    def test_producerSSLFromStart(self):
        """
        C{registerProducer} and C{unregisterProducer} on TLS transports
        created as SSL from the get go are passed to the
        C{TLSMemoryBIOProtocol}, not the underlying transport directly.
        """
        result = []
        producer = FakeProducer()

        runProtocolsWithReactor(self, ConnectableProtocol(),
                                ProducerProtocol(producer, result),
                                SSLCreator())
        self.assertEqual(result, [producer, None])
 def connectionMade(self):
     ConnectableProtocol.connectionMade(self)
     self.events = []
    def test_avoidLeakingFileDescriptors(self):
        """
        If associated with a protocol which does not provide
        L{IFileDescriptorReceiver}, file descriptors received by the
        L{IUNIXTransport} implementation are closed and a warning is emitted.
        """
        # To verify this, establish a connection.  Send one end of the
        # connection over the IUNIXTransport implementation.  After the copy
        # should no longer exist, close the original.  If the opposite end of
        # the connection decides the connection is closed, the copy does not
        # exist.
        from socket import socketpair
        probeClient, probeServer = socketpair()

        events = []
        addObserver(events.append)
        self.addCleanup(removeObserver, events.append)

        class RecordEndpointAddresses(SendFileDescriptor):
            def connectionMade(self):
                self.hostAddress = self.transport.getHost()
                self.peerAddress = self.transport.getPeer()
                SendFileDescriptor.connectionMade(self)

        server = RecordEndpointAddresses(probeClient.fileno(), "junk")
        client = ConnectableProtocol()

        runProtocolsWithReactor(self, server, client, self.endpoints)

        # Get rid of the original reference to the socket.
        probeClient.close()

        # A non-blocking recv will return "" if the connection is closed, as
        # desired.  If the connection has not been closed, because the duplicate
        # file descriptor is still open, it will fail with EAGAIN instead.
        probeServer.setblocking(False)
        self.assertEqual("", probeServer.recv(1024))

        # This is a surprising circumstance, so it should be logged.
        format = ("%(protocolName)s (on %(hostAddress)r) does not "
                  "provide IFileDescriptorReceiver; closing file "
                  "descriptor received (from %(peerAddress)r).")
        clsName = "ConnectableProtocol"

        # Reverse host and peer, since the log event is from the client
        # perspective.
        expectedEvent = dict(hostAddress=server.peerAddress,
                             peerAddress=server.hostAddress,
                             protocolName=clsName,
                             format=format)

        for logEvent in events:
            for k, v in expectedEvent.iteritems():
                if v != logEvent.get(k):
                    break
            else:
                # No mismatches were found, stop looking at events
                break
        else:
            # No fully matching events were found, fail the test.
            self.fail("Expected event (%s) not found in logged events (%s)" %
                      (expectedEvent, pformat(events, )))
 def connectionLost(self, reason):
     ConnectableProtocol.connectionLost(self, reason)
     self.reason = reason
Example #7
0
 def connectionMade(self):
     ConnectableProtocol.connectionMade(self)
     self.events = []
Example #8
0
 def connectionLost(self, reason):
     ConnectableProtocol.connectionLost(self, reason)
     self.reason = reason