listener(
        boost::asio::io_context& ioc,
        tcp::endpoint endpoint)
        : acceptor_(ioc)
        , socket_(ioc)
    {
        boost::system::error_code ec;

        // Open the acceptor
        acceptor_.open(endpoint.protocol(), ec);
        if(ec)
        {
            fail(ec, "open");
            return;
        }

        // Bind to the server address
        acceptor_.bind(endpoint, ec);
        if(ec)
        {
            fail(ec, "bind");
            return;
        }

        // Start listening for connections
        acceptor_.listen(
            boost::asio::socket_base::max_listen_connections, ec);
        if(ec)
        {
            fail(ec, "listen");
            return;
        }
    }
bool TajoSyncClient::connect(const tcp::endpoint &endpoint,
        std::string &errmsg)
{
    boost::system::error_code ec;

    pImpl_->socket_.open(endpoint.protocol(), ec);

    if( !ec )
    {
        pImpl_->socket_.set_option(tcp::no_delay(true), ec);

        if( !ec )
        {
            pImpl_->socket_.connect(endpoint, ec);
        }
    }

    if( !ec )
    {
		pImpl_->state_ = TajoClientState::CONNECTED;
        return true;
    }
    else
    {
        errmsg = ec.message();
        return false;
    }
}
Example #3
0
 void Server::Start(tcp::endpoint endpoint)
 {
     _acceptor.open(endpoint.protocol());
     _acceptor.set_option(tcp::acceptor::reuse_address(true));
     _acceptor.bind(endpoint);
     _acceptor.listen();
     
     _StartAccept();
     
     sLog.Info(LOG_STRATUM, "Stratum server started");
 }
	void seedArm_service_impl::acceptWait(const std::string& addr, const std::string& port
		, size_t workerThreadsCount
		, const size_t keepAliveMilliseconds_GlobalValue)
	{
		if (0 == workerThreadsCount){
			workerThreadsCount = boost::thread::hardware_concurrency();
		}

		////////////////////////////////////////////////
		// set common keepAliveTime
		connection_impl::KEEP_ALIVE_TIME_MS = keepAliveMilliseconds_GlobalValue;



		using TCP = boost::asio::ip::tcp;

		////////////////////////////////////////////////
		// ready accpetor
		TCP::resolver resolver(_ios);
		TCP::resolver::query quary(addr, port);
		TCP::endpoint endpoint = *resolver.resolve(quary);

		_acceptor.open(endpoint.protocol());

		_acceptor.set_option(TCP::no_delay(true));
		_acceptor.set_option(TCP::acceptor::reuse_address(true));
		_acceptor.bind(endpoint);
		_acceptor.listen();

		_acceptConn = connection::ptr(new connection_impl(this, _ios), connection_impl::destruct);
		_acceptor.async_accept(_acceptConn->socket(), _strand.wrap(
			boost::bind(&seedArm_service_impl::accept, this, boost::asio::placeholders::error)));


		////////////////////////////////////////////////
		// ready worker
		for (size_t i = 0; i < workerThreadsCount; ++i)
		{
			boost::shared_ptr<boost::thread> thread(new boost::thread(
				boost::bind(&boost::asio::io_service::run, &_ios)));

			s_threads.push_back(thread);
		}


		////////////////////////////////////////////////
		// ready expireTimer
		_prevTime = boost::chrono::system_clock::now();
		_updater.expires_from_now(boost::posix_time::milliseconds(UPDATE_TIME_MS));

		_updater.async_wait(_strand.wrap(
			boost::bind(&seedArm_service_impl::update, this, boost::asio::placeholders::error)));
	}
Example #5
0
void worker::add_endpoint(tcp::endpoint& ep, bs::error_code& ec) {
    try {
        auto acceptor = tcp::acceptor(m_iosvc);
        acceptor.open(ep.protocol());
        acceptor.set_option(tcp::acceptor::reuse_address(true));
        acceptor.bind(ep);
        int backlog = options::opts["server.backlog"].as<int>();
        if (backlog == 0) {
            backlog = ba::socket_base::max_connections;
        }
        acceptor.listen(backlog);
        m_acceptors.push_back(std::move(acceptor));
    } catch (bs::system_error& e) {
        ec = e.code();
    }
}
    /** Open a listening port.

        @param ep The address and port to bind to.

        @param ec Set to the error, if any occurred.
    */
    void
    open(tcp::endpoint const& ep, error_code& ec)
    {
        acceptor_.open(ep.protocol(), ec);
        if(ec)
            return fail("open", ec);
        acceptor_.set_option(
            boost::asio::socket_base::reuse_address{true});
        acceptor_.bind(ep, ec);
        if(ec)
            return fail("bind", ec);
        acceptor_.listen(
            boost::asio::socket_base::max_connections, ec);
        if(ec)
            return fail("listen", ec);
        do_accept();
    }
    listener(
        boost::asio::io_context& ioc,
        ssl::context& ctx,
        tcp::endpoint endpoint)
        : ctx_(ctx)
        , acceptor_(ioc)
        , socket_(ioc)
    {
        boost::system::error_code ec;

        // Open the acceptor
        acceptor_.open(endpoint.protocol(), ec);
        if(ec)
        {
            fail(ec, "open");
            return;
        }

        // Allow address reuse
        acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec);
        if(ec)
        {
            fail(ec, "set_option");
            return;
        }

        // Bind to the server address
        acceptor_.bind(endpoint, ec);
        if(ec)
        {
            fail(ec, "bind");
            return;
        }

        // Start listening for connections
        acceptor_.listen(
            boost::asio::socket_base::max_listen_connections, ec);
        if(ec)
        {
            fail(ec, "listen");
            return;
        }
    }