adds asio transport eof error detection

This commit is contained in:
Peter Thorson
2013-04-20 08:33:53 -05:00
parent f877098f7c
commit ea3426868c
2 changed files with 23 additions and 9 deletions

View File

@@ -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) {

View File

@@ -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";
}