bool connection_handler::do_run()
{
    // initialize network
    std::size_t tried = 0;
    exception_list errors;
    naming::locality::iterator_type end = accept_end(here_);
    for (naming::locality::iterator_type it =
                accept_begin(here_, io_service_pool_.get_io_service(0), true);
            it != end; ++it, ++tried)
    {
        try {
            boost::asio::ip::tcp::endpoint ep = *it;

            acceptor_.bind(ep, boost::system::throws);
            ++tried;
            break;
        }
        catch (boost::system::system_error const& e) {
            errors.add(e);   // store all errors
            continue;
        }
    }

    if (errors.get_error_count() == tried) {
        // all attempts failed
        HPX_THROW_EXCEPTION(network_error,
                            "ibverbs::connection_handler::run", errors.get_message());
        return false;
    }
    time_send = 0;
    time_recv = 0;
    time_acct = 0;

    handling_accepts_ = true;
    boost::asio::io_service& io_service = io_service_pool_.get_io_service(1);
    io_service.post(HPX_STD_BIND(&connection_handler::handle_accepts, this));

    background_work();
    return true;
}
Beispiel #2
0
 endpoint_iterator_type accept_begin(Locality const& loc,
     boost::asio::io_service& io_service)
 {
     return accept_begin(loc.address(), loc.port(), io_service);
 }