/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include #include #include #include "Swiften/Base/boost_bsignals.h" #include "Swiften/Network/BoostConnection.h" #include "Swiften/Network/ConnectionServer.h" #include "Swiften/EventLoop/EventOwner.h" namespace Swift { class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this { public: typedef boost::shared_ptr ref; enum Error { Conflict, UnknownError }; static ref create(int port, boost::asio::io_service* ioService, EventLoop* eventLoop) { return ref(new BoostConnectionServer(port, ioService, eventLoop)); } void start(); void stop(); virtual HostAddressPort getAddressPort() const; boost::signal)> onStopped; private: BoostConnectionServer(int port, boost::asio::io_service* ioService, EventLoop* eventLoop); void stop(boost::optional e); void acceptNextConnection(); void handleAccept(boost::shared_ptr newConnection, const boost::system::error_code& error); private: int port_; boost::asio::io_service* ioService_; EventLoop* eventLoop; boost::asio::ip::tcp::acceptor* acceptor_; }; }