3 #include <boost/thread.hpp>
6 #include <boost/scope_exit.hpp>
15 _completion_promise(completion_promise)
23 _completion_promise->
set_value(bytes_transferred);
24 else if( ec == boost::asio::error::eof )
26 _completion_promise->
set_exception( std::make_shared<fc::eof_exception>(
28 (
"message", boost::system::system_error(ec).what())) ) );
30 else if( ec == boost::asio::error::operation_aborted )
32 _completion_promise->
set_exception( std::make_shared<fc::canceled_exception>(
34 (
"message", boost::system::system_error(ec).what())) ) );
38 _completion_promise->
set_exception( std::make_shared<fc::exception>(
40 (
"message", boost::system::system_error(ec).what())) ) );
44 const std::shared_ptr<const char>& buffer) :
45 _completion_promise(completion_promise),
51 _completion_promise->
set_value(bytes_transferred);
52 else if( ec == boost::asio::error::eof )
54 _completion_promise->
set_exception( std::make_shared<fc::eof_exception>(
56 (
"message", boost::system::system_error(ec).what())) ) );
58 else if( ec == boost::asio::error::operation_aborted )
60 _completion_promise->
set_exception( std::make_shared<fc::canceled_exception>(
62 (
"message", boost::system::system_error(ec).what())) ) );
66 _completion_promise->
set_exception( std::make_shared<fc::exception>(
68 (
"message", boost::system::system_error(ec).what())) ) );
73 const boost::system::error_code& ec,
size_t bytes_transferred ) {
78 const boost::system::error_code& ec ) {
83 if( ec == boost::asio::error::eof )
87 (
"message", boost::system::system_error(ec).what())) ) );
89 else if( ec == boost::asio::error::operation_aborted )
93 (
"message", boost::system::system_error(ec).what())) ) );
99 (
"message", boost::system::system_error(ec).what())) ) );
105 const boost::system::error_code& ec ) {
109 template<
typename Endpo
intType,
typename IteratorType>
111 const typename promise<std::vector<EndpointType> >::ptr& p,
112 const boost::system::error_code& ec,
115 std::vector<EndpointType> eps;
116 while( itr != IteratorType() ) {
125 (
"message", boost::system::system_error(ec).what())) ) ) );
152 io =
new boost::asio::io_service();
153 the_work =
new boost::asio::io_service::work(*
io);
159 num_io_threads = std::max( boost::thread::hardware_concurrency(), 8U );
164 asio_threads.push_back(
new boost::thread( [i,
this]()
168 BOOST_SCOPE_EXIT(
void)
174 while (!
io->stopped())
182 elog(
"Caught unhandled exception in asio service loop: ${e}", (
"e", e));
184 catch (
const std::exception& e)
186 elog(
"Caught unhandled exception in asio service loop: ${e}", (
"e", e.what()));
190 elog(
"Caught unhandled exception in asio service loop");
204 for(
auto asio_thread : asio_threads )
209 for(
auto asio_thread : asio_threads )
221 return *fc_asio_service[0].
io;
225 std::vector<boost::asio::ip::tcp::endpoint>
resolve(
const std::string& hostname,
const std::string& port)
231 res.async_resolve( boost::asio::ip::tcp::resolver::query(hostname,port),
232 boost::bind( detail::resolve_handler<boost::asio::ip::tcp::endpoint,resolver_iterator>, p, _1, _2 ) );
239 std::vector<udp::endpoint>
resolve(
resolver& r,
const std::string& hostname,
const std::string& port)
245 res.async_resolve( resolver::query(hostname,port),
246 boost::bind( detail::resolve_handler<endpoint,resolver_iterator>, p, _1, _2 ) );