diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 7f3fcb2312..94e795d548 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -199,17 +199,26 @@ protected: void handle_async_read(read_handler handler, const boost::system::error_code& ec, size_t bytes_transferred) { - // TODO: translate this better - if (ec) { + if (!ec) { + handler(lib::error_code(), bytes_transferred); + return; + } + + // translate boost error codes into more lib::error_codes + if (ec == boost::asio::error::eof) { + handler(make_error_code(transport::error::eof), + bytes_transferred); + } else { + // other error that we cannot translate into a WebSocket++ + // transport error. Use pass through and print an info warning + // with the original error. std::stringstream s; s << "asio async_read_at_least error::pass_through" << ", Original Error: " << ec << " (" << ec.message() << ")"; - m_elog.write(log::elevel::devel,s.str()); - handler(make_error_code(transport::error::pass_through), - bytes_transferred); - } else { - handler(lib::error_code(), bytes_transferred); - } + m_elog.write(log::elevel::info,s.str()); + handler(make_error_code(transport::error::pass_through), + bytes_transferred); + } } void async_write(const char* buf, size_t len, write_handler handler) { diff --git a/websocketpp/transport/base/connection.hpp b/websocketpp/transport/base/connection.hpp index 1255c2573b..a84064d5ad 100644 --- a/websocketpp/transport/base/connection.hpp +++ b/websocketpp/transport/base/connection.hpp @@ -101,7 +101,10 @@ enum value { operation_aborted, /// Operation not supported - operation_not_supported + operation_not_supported, + + /// End of file + eof }; class category : public lib::error_category { @@ -124,6 +127,8 @@ class category : public lib::error_category { return "The operation was aborted"; case operation_not_supported: return "The operation is not supported by this transport"; + case eof: + return "End of File"; default: return "Unknown"; }