diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-08-01 17:49:35 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-08-01 17:49:35 (GMT) |
commit | 3a4c1c7a6fd03fed0bdfc3acc85d60ec1797361c (patch) | |
tree | 546b28d7970ef4b2bd719b04a3ec32530df8d680 /Swiften/Network | |
parent | d856cc05a54eabe3014b8512b27192c9e8da35ff (diff) | |
download | swift-contrib-3a4c1c7a6fd03fed0bdfc3acc85d60ec1797361c.zip swift-contrib-3a4c1c7a6fd03fed0bdfc3acc85d60ec1797361c.tar.bz2 |
Added LinkLocalConnector::cancel().
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/FakeConnection.h | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/Swiften/Network/FakeConnection.h b/Swiften/Network/FakeConnection.h index 076a1f1..92a03c3 100644 --- a/Swiften/Network/FakeConnection.h +++ b/Swiften/Network/FakeConnection.h @@ -16,7 +16,15 @@ namespace Swift { public EventOwner, public boost::enable_shared_from_this<FakeConnection> { public: - FakeConnection() {} + enum State { + Initial, + Connecting, + Connected, + Disconnected, + DisconnectedWithError + }; + + FakeConnection() : state(Initial), delayConnect(false) {} virtual void listen() { assert(false); @@ -24,6 +32,7 @@ namespace Swift { void setError(const Error& e) { error = boost::optional<Error>(e); + state = DisconnectedWithError; if (connectedTo) { MainEventLoop::postEvent( boost::bind(boost::ref(onDisconnected), error), @@ -32,15 +41,31 @@ namespace Swift { } virtual void connect(const HostAddressPort& address) { - if (!error) { - connectedTo = address; + if (delayConnect) { + state = Connecting; + } + else { + if (!error) { + connectedTo = address; + state = Connected; + } + else { + state = DisconnectedWithError; + } + MainEventLoop::postEvent( + boost::bind(boost::ref(onConnectFinished), error), + shared_from_this()); } - MainEventLoop::postEvent( - boost::bind(boost::ref(onConnectFinished), error), - shared_from_this()); } virtual void disconnect() { + if (!error) { + state = Disconnected; + } + else { + state = DisconnectedWithError; + } + connectedTo.reset(); MainEventLoop::postEvent( boost::bind(boost::ref(onDisconnected), error), shared_from_this()); @@ -50,8 +75,14 @@ namespace Swift { dataWritten.push_back(data); } + void setDelayConnect() { + delayConnect = true; + } + boost::optional<HostAddressPort> connectedTo; std::vector<ByteArray> dataWritten; boost::optional<Error> error; + State state; + bool delayConnect; }; } |