summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/BoostConnectionServer.cpp')
m---------Swiften0
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp68
2 files changed, 0 insertions, 68 deletions
diff --git a/Swiften b/Swiften
new file mode 160000
+Subproject 8213ba16d0043d2461f4b031c881d61dda5a38c
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
deleted file mode 100644
index cea016d..0000000
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#include "Swiften/Network/BoostConnectionServer.h"
-
-#include <boost/bind.hpp>
-#include <boost/system/system_error.hpp>
-
-#include "Swiften/EventLoop/MainEventLoop.h"
-
-namespace Swift {
-
-BoostConnectionServer::BoostConnectionServer(int port, boost::asio::io_service* ioService) : port_(port), ioService_(ioService), acceptor_(NULL) {
-}
-
-
-void BoostConnectionServer::start() {
- try {
- assert(!acceptor_);
- acceptor_ = new boost::asio::ip::tcp::acceptor(
- *ioService_,
- boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port_));
- acceptNextConnection();
- }
- catch (const boost::system::system_error& e) {
- if (e.code() == boost::asio::error::address_in_use) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onStopped), Conflict), shared_from_this());
- }
- else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onStopped), UnknownError), shared_from_this());
- }
- }
-}
-
-
-void BoostConnectionServer::stop() {
- stop(boost::optional<Error>());
-}
-
-void BoostConnectionServer::stop(boost::optional<Error> e) {
- if (acceptor_) {
- acceptor_->close();
- delete acceptor_;
- acceptor_ = NULL;
- }
- MainEventLoop::postEvent(boost::bind(boost::ref(onStopped), e), shared_from_this());
-}
-
-void BoostConnectionServer::acceptNextConnection() {
- boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_->io_service()));
- acceptor_->async_accept(newConnection->getSocket(),
- boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
-}
-
-void BoostConnectionServer::handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error) {
- if (error) {
- MainEventLoop::postEvent(
- boost::bind(
- &BoostConnectionServer::stop, shared_from_this(), UnknownError),
- shared_from_this());
- }
- else {
- MainEventLoop::postEvent(
- boost::bind(boost::ref(onNewConnection), newConnection),
- shared_from_this());
- newConnection->listen();
- acceptNextConnection();
- }
-}
-
-}