diff --git a/include/fc/asio.hpp b/include/fc/asio.hpp index 9310774..57da7a1 100644 --- a/include/fc/asio.hpp +++ b/include/fc/asio.hpp @@ -39,17 +39,8 @@ namespace asio { std::shared_ptr _buffer; }; - //void read_write_handler( const promise::ptr& p, - // const boost::system::error_code& ec, - // size_t bytes_transferred ); - void read_write_handler_ec( promise* p, - boost::system::error_code* oec, - const boost::system::error_code& ec, - size_t bytes_transferred ); void error_handler( const promise::ptr& p, - const boost::system::error_code& ec ); - void error_handler_ec( promise* p, - const boost::system::error_code& ec ); + const boost::system::error_code& ec ); template struct non_blocking { @@ -57,14 +48,14 @@ namespace asio { bool operator()( C& c, bool s ) { c.non_blocking(s); return true; } }; - #if WIN32 // windows stream handles do not support non blocking! - template<> - struct non_blocking { - typedef boost::asio::windows::stream_handle C; - bool operator()( C& ) { return false; } - bool operator()( C&, bool ) { return false; } +#if WIN32 // windows stream handles do not support non blocking! + template<> + struct non_blocking { + typedef boost::asio::windows::stream_handle C; + bool operator()( C& ) { return false; } + bool operator()( C&, bool ) { return false; } }; - #endif +#endif } /** * @return the default boost::asio::io_service for use with fc::asio diff --git a/src/asio.cpp b/src/asio.cpp index 8f6bff0..c2499aa 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -10,11 +10,12 @@ namespace fc { read_write_handler::read_write_handler(const promise::ptr& completion_promise) : _completion_promise(completion_promise) { - // assert(false); // to detect anywhere we're not passing in a shared buffer + //assert(false); // to detect anywhere we're not passing in a shared buffer } + void read_write_handler::operator()(const boost::system::error_code& ec, size_t bytes_transferred) { - // assert(false); // to detect anywhere we're not passing in a shared buffer + //assert(false); // to detect anywhere we're not passing in a shared buffer if( !ec ) _completion_promise->set_value(bytes_transferred); else if( ec == boost::asio::error::eof ) @@ -22,11 +23,13 @@ namespace fc { else _completion_promise->set_exception( fc::exception_ptr( new fc::exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); } + read_write_handler_with_buffer::read_write_handler_with_buffer(const promise::ptr& completion_promise, const std::shared_ptr& buffer) : _completion_promise(completion_promise), _buffer(buffer) {} + void read_write_handler_with_buffer::operator()(const boost::system::error_code& ec, size_t bytes_transferred) { if( !ec ) @@ -37,57 +40,53 @@ namespace fc { _completion_promise->set_exception( fc::exception_ptr( new fc::exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); } - void read_write_handler_ec( promise* p, boost::system::error_code* oec, const boost::system::error_code& ec, size_t bytes_transferred ) { - p->set_value(bytes_transferred); - *oec = ec; - } - void error_handler( const promise::ptr& p, - const boost::system::error_code& ec ) { - if( !ec ) - p->set_value(); - else - { - if( ec == boost::asio::error::eof ) - { - p->set_exception( fc::exception_ptr( new fc::eof_exception( - FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); - } - else - { - //elog( "${message} ", ("message", boost::system::system_error(ec).what())); - p->set_exception( fc::exception_ptr( new fc::exception( - FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); - } - } + void error_handler( const promise::ptr& p, + const boost::system::error_code& ec ) + { + if( !ec ) + p->set_value(); + else + { + if( ec == boost::asio::error::eof ) + { + p->set_exception( fc::exception_ptr( new fc::eof_exception( + FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + } + else + { + //elog( "${message} ", ("message", boost::system::system_error(ec).what())); + p->set_exception( fc::exception_ptr( new fc::exception( + FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + } } + } - void error_handler_ec( promise* p, - const boost::system::error_code& ec ) { - p->set_value(ec); + template + void resolve_handler(const typename promise >::ptr& p, + const boost::system::error_code& ec, + IteratorType itr) + { + if( !ec ) + { + std::vector eps; + while( itr != IteratorType() ) + { + eps.push_back(*itr); + ++itr; + } + p->set_value( eps ); } - - template - void resolve_handler( - const typename promise >::ptr& p, - const boost::system::error_code& ec, - IteratorType itr) { - if( !ec ) { - std::vector eps; - while( itr != IteratorType() ) { - eps.push_back(*itr); - ++itr; - } - p->set_value( eps ); - } else { - //elog( "%s", boost::system::system_error(ec).what() ); - //p->set_exception( fc::copy_exception( boost::system::system_error(ec) ) ); - p->set_exception( - fc::exception_ptr( new fc::exception( - FC_LOG_MESSAGE( error, "process exited with: ${message} ", - ("message", boost::system::system_error(ec).what())) ) ) ); - } + else + { + //elog( "%s", boost::system::system_error(ec).what() ); + //p->set_exception( fc::copy_exception( boost::system::system_error(ec) ) ); + p->set_exception( + fc::exception_ptr( new fc::exception( + FC_LOG_MESSAGE( error, "process exited with: ${message} ", + ("message", boost::system::system_error(ec).what())) ) ) ); } - } + } + } // end namespace detail struct default_io_service_scope {