From 91c1458af5fc12f4f7728b4ade254bbf0e80bcab Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 18 Nov 2023 16:26:04 +0000 Subject: [PATCH] Rethrow more asio operation cancel exception ... ... `boost::asio::error::operation_aborted` as `fc::canceled_exception` instead of `fc::exception` in read/write handlers --- src/asio.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/asio.cpp b/src/asio.cpp index 494df5ec..dda9e93b 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -22,9 +22,23 @@ namespace fc { if( !ec ) _completion_promise->set_value(bytes_transferred); else if( ec == boost::asio::error::eof ) - _completion_promise->set_exception( fc::exception_ptr( new fc::eof_exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + { + _completion_promise->set_exception( std::make_shared( + FC_LOG_MESSAGE( error, "${message} ", + ("message", boost::system::system_error(ec).what())) ) ); + } + else if( ec == boost::asio::error::operation_aborted ) + { + _completion_promise->set_exception( std::make_shared( + FC_LOG_MESSAGE( error, "${message} ", + ("message", boost::system::system_error(ec).what())) ) ); + } else - _completion_promise->set_exception( fc::exception_ptr( new fc::exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + { + _completion_promise->set_exception( std::make_shared( + 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) : @@ -36,12 +50,27 @@ namespace fc { if( !ec ) _completion_promise->set_value(bytes_transferred); else if( ec == boost::asio::error::eof ) - _completion_promise->set_exception( fc::exception_ptr( new fc::eof_exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + { + _completion_promise->set_exception( std::make_shared( + FC_LOG_MESSAGE( error, "${message} ", + ("message", boost::system::system_error(ec).what())) ) ); + } + else if( ec == boost::asio::error::operation_aborted ) + { + _completion_promise->set_exception( std::make_shared( + FC_LOG_MESSAGE( error, "${message} ", + ("message", boost::system::system_error(ec).what())) ) ); + } else - _completion_promise->set_exception( fc::exception_ptr( new fc::exception( FC_LOG_MESSAGE( error, "${message} ", ("message", boost::system::system_error(ec).what())) ) ) ); + { + _completion_promise->set_exception( std::make_shared( + 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 ) { + 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; }