/* * Copyright (c) 2010 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Swift { class SWIFTEN_API BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this { public: typedef boost::shared_ptr ref; static ref create(int port, boost::shared_ptr ioService, EventLoop* eventLoop) { return ref(new BoostConnectionServer(port, ioService, eventLoop)); } static ref create(const HostAddress &address, int port, boost::shared_ptr ioService, EventLoop* eventLoop) { return ref(new BoostConnectionServer(address, port, ioService, eventLoop)); } virtual boost::optional tryStart(); // FIXME: This should become the new start virtual void start(); virtual void stop(); virtual HostAddressPort getAddressPort() const; boost::signal)> onStopped; private: BoostConnectionServer(int port, boost::shared_ptr ioService, EventLoop* eventLoop); BoostConnectionServer(const HostAddress &address, int port, boost::shared_ptr ioService, EventLoop* eventLoop); void stop(boost::optional e); void acceptNextConnection(); void handleAccept(boost::shared_ptr newConnection, const boost::system::error_code& error); private: HostAddress address_; int port_; boost::shared_ptr ioService_; EventLoop* eventLoop; boost::asio::ip::tcp::acceptor* acceptor_; }; }