diff options
| author | Remko Tronçon <git@el-tramo.be> | 2013-04-08 17:25:21 (GMT) | 
|---|---|---|
| committer | Swift Review <review@swift.im> | 2013-04-11 19:20:50 (GMT) | 
| commit | 4ec2390efec7cfdd411c7bb14e9f77ec9ee5c005 (patch) | |
| tree | b52419c9c08419cef8609fc5ed0e8bb9f03f1c02 /Swiften/Network/BoostConnectionServer.cpp | |
| parent | 7d9c895ba6f1cdb56925a5313b989ecb2c5217fa (diff) | |
| download | swift-4ec2390efec7cfdd411c7bb14e9f77ec9ee5c005.zip swift-4ec2390efec7cfdd411c7bb14e9f77ec9ee5c005.tar.bz2 | |
Network refactoring.
Provide sync connection server start method.
Provide NetworkEnvironment through NetworkFactories.
Change-Id: Iea04349255af8aa6326968f17653e8e371a08bdd
Diffstat (limited to 'Swiften/Network/BoostConnectionServer.cpp')
| -rw-r--r-- | Swiften/Network/BoostConnectionServer.cpp | 13 | 
1 files changed, 11 insertions, 2 deletions
| diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp index e015eaa..c90b554 100644 --- a/Swiften/Network/BoostConnectionServer.cpp +++ b/Swiften/Network/BoostConnectionServer.cpp @@ -10,6 +10,7 @@  #include <boost/system/system_error.hpp>  #include <boost/asio/placeholders.hpp>  #include <boost/numeric/conversion/cast.hpp> +#include <boost/optional.hpp>  #include <Swiften/EventLoop/EventLoop.h> @@ -22,6 +23,13 @@ BoostConnectionServer::BoostConnectionServer(const HostAddress &address, int por  }  void BoostConnectionServer::start() { +	boost::optional<Error> error = tryStart(); +	if (error) { +		eventLoop->postEvent(boost::bind(boost::ref(onStopped), *error), shared_from_this()); +	} +} + +boost::optional<BoostConnectionServer::Error> BoostConnectionServer::tryStart() {  	try {  		assert(!acceptor_);  		if (address_.isValid()) { @@ -38,12 +46,13 @@ void BoostConnectionServer::start() {  	}  	catch (const boost::system::system_error& e) {  		if (e.code() == boost::asio::error::address_in_use) { -			eventLoop->postEvent(boost::bind(boost::ref(onStopped), Conflict), shared_from_this()); +			return Conflict;  		}  		else { -			eventLoop->postEvent(boost::bind(boost::ref(onStopped), UnknownError), shared_from_this()); +			return UnknownError;  		}  	} +	return boost::optional<Error>();  } | 
 Swift
 Swift