示例#1
0
 def onClose(self, wasClean, code, reason):
     if self.wormhole_open:
         self.wormhole._ws_closed(wasClean, code, reason)
     else:
         # we closed before establishing a connection (onConnect) or
         # finishing WebSocket negotiation (onOpen): errback
         self.factory.d.errback(error.ConnectError(reason))
示例#2
0
 def connectionLost(self, reason):
     if not self.connected:
         self.failIfNotConnected(error.ConnectError(string=reason))
     else:
         df = maybeDeferred(Connection.connectionLost, self, reason)
         def more(r):
             self.connector.connectionLost(reason)
         df.addCallback(more)
示例#3
0
class ConnectExOp(OverlappedOp):
    def ovDone(self, ret, bytes, (handle, sock)):
        if ret:
#            print "ConnectExOp err", ret
            self.transport.connectErr(failure.Failure(error.errnoMapping.get(winerrcodeMapping.get(ret), error.ConnectError)())) # finish the mapping in error.py
        else:
            if have_connectex:
                try:
                    sock.setsockopt(socket.SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, "")
                except socket.error, se:
                    self.transport.connectErr(failure.Failure(error.ConnectError()))
            self.transport.connectDone()
示例#4
0
    def connectionLost(self, reason):
        """
        Invoked by lower-level logic when it's time to clean the socket up.
        Depending on the state of the connection, either inform the attached
        L{Connector} that the connection attempt has failed, or inform the
        connected L{IProtocol} that the established connection has been lost.

        @param reason: the reason that the connection was terminated
        @type reason: L{Failure}
        """
        if not self.connected:
            self.failIfNotConnected(error.ConnectError(string=reason))
        else:
            self._commonConnection.connectionLost(self, reason)
            self.connector.connectionLost(reason)
示例#5
0
 def test_try_handled_error(self):
     reactor = object()
     txi2p = mock.Mock()
     d = defer.fail(error.ConnectError("oops"))
     txi2p.testAPI = mock.Mock(return_value=d)
     ep = object()
     stdout = StringIO()
     with mock.patch("allmydata.util.i2p_provider.clientFromString",
                     return_value=ep) as cfs:
         d = i2p_provider._try_to_connect(reactor, "desc", stdout, txi2p)
     r = self.successResultOf(d)
     self.assertIs(r, None)
     cfs.assert_called_with(reactor, "desc")
     txi2p.testAPI.assert_called_with(reactor, 'SAM', ep)
     self.assertEqual(stdout.getvalue(),
                      "Unable to reach I2P SAM API at 'desc': "
                      "An error occurred while connecting: oops.\n")
示例#6
0
    def test_clientConnectionFailed(self):
        """
        Calls to L{_WrappingFactory.clientConnectionLost} should errback the
        L{_WrappingFactory._onConnection} L{Deferred}
        """
        wf = endpoints._WrappingFactory(TestFactory(), None)
        expectedFailure = Failure(error.ConnectError(string="fail"))

        wf.clientConnectionFailed(None, expectedFailure)

        errors = []

        def gotError(f):
            errors.append(f)

        wf._onConnection.addErrback(gotError)

        self.assertEquals(errors, [expectedFailure])
    def logOn(self, chatui):
        """Log on to this account.

        Takes care to not start a connection if a connection is
        already in progress.  You will need to implement
        L{_startLogOn} for this to work, and it would be a good idea
        to override L{_loginFailed} too.

        @returntype: Deferred L{interfaces.IClient}
        """
        if (not self._isConnecting) and (not self._isOnline):
            self._isConnecting = 1
            d = self._startLogOn(chatui)
            d.addCallback(self._cb_logOn)
            # if chatui is not None:
            # (I don't particularly like having to pass chatUI to this function,
            # but we haven't factored it out yet.)
            d.addCallback(chatui.registerAccountClient)
            d.addErrback(self._loginFailed)
            return d
        else:
            raise error.ConnectError("Connection in progress")
示例#8
0
    def test_endpointConnectFailure(self):
        """
        If an endpoint tries to connect to a non-listening port it gets
        a C{ConnectError} failure.
        """
        expectedError = error.ConnectError(string="Connection Failed")

        mreactor = RaisingMemoryReactor(connectException=expectedError)

        clientFactory = object()

        ep, ignoredArgs, ignoredDest = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)

        receivedExceptions = []

        def checkFailure(f):
            receivedExceptions.append(f.value)

        d.addErrback(checkFailure)

        self.assertEquals(receivedExceptions, [expectedError])
 def connectionLost(self, reason):
     if not self.connected:
         self.failIfNotConnected(error.ConnectError(string=reason))
     else:
         Connection.connectionLost(self, reason)
         self.connector.connectionLost(reason)
示例#10
0
 def connect(self, *args, **kw):
     ports_attempted.append(self.tor_port)
     if self.tor_port != 9150:
         return Failure(error.ConnectError("foo"))
     else:
         return proto