Boost logo

Boost Users :

Subject: [Boost-users] Compare boost::system::error_category
From: Christopher Pisz (christopherpisz_at_[hidden])
Date: 2017-03-23 20:26:02


The following comparison fails for an error whom outputs "asio.misc" for
errorCode.category().name() and "end of file" for errorCode.message()

If it claims to be in category asio.misc, then why does the if condition of
(errorCode.category() == boost::asio::error::misc_category ) evaluate to
false?

Googling says that a boost::system::error_code can have the same value in
more than one category, so I assume that in order to get the proper message
and meaning we must compare boost::system::error_category as well as
boost::system::error_code::value.

How do we properly compare the category if this fails to work?

Code in question:
//--------------------------------------------------------------------------------------------------
std::string ClientSocketASIO::ErrorCodeToString(const
boost::system::error_code & errorCode)
{
    std::ostringstream debugMsg;
    debugMsg << " Error Category: " << errorCode.category().name() << ". "
             << " Error Message: " << errorCode.message() << ". ";

    if( errorCode.category() == boost::asio::error::misc_category )
    {
        switch (errorCode.value())
        {
        case boost::asio::error::eof:
            debugMsg << ". Server has disconnected.";
            break;
        case boost::asio::error::connection_refused:
            debugMsg << ". Connection Refused";
            break;
        default:
            debugMsg << ". Unknown Error.";
            break;
        }
    }
    else
    {
        debugMsg << ". Unknown Error category.";
    }

    return debugMsg.str();
}

--
View this message in context: http://boost.2283326.n4.nabble.com/Compare-boost-system-error-category-tp4692861.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net