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 )
30 const std::shared_ptr<const char>& buffer) :
31 _completion_promise(completion_promise),
37 _completion_promise->
set_value(bytes_transferred);
38 else if( ec == boost::asio::error::eof )
49 const boost::system::error_code& ec ) {
54 if( ec == boost::asio::error::eof )
57 FC_LOG_MESSAGE( error,
"${message} ", (
"message", boost::system::system_error(ec).what())) ) ) );
62 FC_LOG_MESSAGE( error,
"${message} ", (
"message", boost::system::system_error(ec).what())) ) ) );
68 const boost::system::error_code& ec ) {
72 template<
typename Endpo
intType,
typename IteratorType>
74 const typename promise<std::vector<EndpointType> >::ptr& p,
75 const boost::system::error_code& ec,
78 std::vector<EndpointType> eps;
79 while( itr != IteratorType() ) {
88 (
"message", boost::system::system_error(ec).what())) ) ) );
105 num_io_threads = num_threads;
115 io =
new boost::asio::io_service();
116 the_work =
new boost::asio::io_service::work(*io);
118 if( num_io_threads == 0 )
122 num_io_threads = std::max( boost::thread::hardware_concurrency(), 8U );
125 for( uint16_t i = 0; i < num_io_threads; ++i )
127 asio_threads.push_back(
new boost::thread( [i,
this]()
131 BOOST_SCOPE_EXIT(
void)
137 while (!io->stopped())
145 elog(
"Caught unhandled exception in asio service loop: ${e}", (
"e", e));
147 catch (
const std::exception& e)
149 elog(
"Caught unhandled exception in asio service loop: ${e}", (
"e", e.what()));
153 elog(
"Caught unhandled exception in asio service loop");
167 for(
auto asio_thread : asio_threads )
172 for(
auto asio_thread : asio_threads )
184 return *fc_asio_service[0].
io;
188 std::vector<boost::asio::ip::tcp::endpoint>
resolve(
const std::string& hostname,
const std::string& port)
194 res.async_resolve( boost::asio::ip::tcp::resolver::query(hostname,port),
195 boost::bind( detail::resolve_handler<boost::asio::ip::tcp::endpoint,resolver_iterator>, p, _1, _2 ) );
202 std::vector<udp::endpoint>
resolve(
resolver& r,
const std::string& hostname,
const std::string& port)
208 res.async_resolve( resolver::query(hostname,port),
209 boost::bind( detail::resolve_handler<endpoint,resolver_iterator>, p, _1, _2 ) );
void read_write_handler_ec(promise< size_t > *p, boost::system::error_code *oec, const boost::system::error_code &ec, size_t bytes_transferred)
boost::asio::ip::tcp::resolver resolver
void error_handler(const promise< void >::ptr &p, const boost::system::error_code &ec)
void operator()(const boost::system::error_code &ec, size_t bytes_transferred)
void set_exception(const fc::exception_ptr &e)
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
~default_io_service_scope()
void set_name(const string &n)
associates a name with this thread.
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
std::shared_ptr< exception > exception_ptr
const T & wait(const microseconds &timeout=microseconds::maximum())
static thread & current()
void error_handler_ec(promise< boost::system::error_code > *p, const boost::system::error_code &ec)
void set_value(const T &v)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
static uint16_t get_num_threads()
boost::asio::ip::udp::resolver resolver
default_io_service_scope()
read_write_handler(const promise< size_t >::ptr &p)
Defines exception's used by fc.
void resolve_handler(const typename promise< std::vector< EndpointType > >::ptr &p, const boost::system::error_code &ec, IteratorType itr)
boost::asio::io_service * io
std::string to_string(double)
boost::asio::io_service & default_io_service()
std::vector< fc::ip::endpoint > resolve(const std::string &host, uint16_t port)
read_write_handler_with_buffer(const promise< size_t >::ptr &p, const std::shared_ptr< const char > &buffer)
static uint16_t num_io_threads
#define FC_LOG_MESSAGE(LOG_LEVEL, FORMAT,...)
A helper method for generating log messages.
void operator()(const boost::system::error_code &ec, size_t bytes_transferred)
std::shared_ptr< promise< T > > ptr
static void set_num_threads(uint16_t num_threads)