errorCode.category() 및 errorCode.message()의 "end of file"에 대해 "asio.misc"를 출력하는 오류에 대해 다음 비교가 실패합니다.비교 boost :: system :: error_category
범주 asio.misc에 있다고 주장하면 (errorCode.category() == boost :: asio :: error :: misc_category의 if 조건이 false로 평가되는 이유는 무엇입니까?
인터넷 검색 : boost :: system :: error_code는 둘 이상의 카테고리에서 동일한 값을 가질 수 있으므로 올바른 메시지와 의미를 얻으려면 boost :: system :: error_category뿐만 아니라 boost :: system :: error_code :: value.
카테고리가 제대로 작동하지 않으면 어떻게 비교합니까? 문제
코드 : https://theboostcpplibraries.com/boost.system 및 Boost::file_system: Checking error codes
일반적으로하고 실수 사람들 만이 오류 값이 아닌 범주를 비교하는 코드를 작성에 따르면
:
편집
이//--------------------------------------------------------------------------------------------------
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();
}
. 오류 값 만이 고유하지 않으며 둘 이상의 범주에서 발생할 수 있습니다. 사용자는 자신의 오류 코드 및 범주를 자유롭게 만들 수 있습니다. 따라서 둘을 비교해야합니다. 어쨌든 하나의 기능이나 라이브러리를 사용하기 때문에 많은 수의 응용 프로그램에 영향을 미치지 않습니다. 대부분의 오류 코드는 Windows 오류 코드에 매핑되어 있지 않습니다. 충돌.
내 작업이 거의 모든 것을 차단 했으므로 메일 링리스트를 높이기 위해 다른 컴퓨터를 사용해야했습니다.
http://boost.2283326.n4.nabble.com/Compare-boost-system-error-category-td4692861.html#a4692869
저기 FELLA에 따르면, 상기 비교는 실패의 이유는, 부스트 라이브러리 정적으로 링크되어 있기 때문에, 그리고 부스트 : 시스템 : error_category :: 연산자 == 어드레스를 비교하므로 LHS 하나의 lib에있는 주소이고 RHS는 다른 lib에있는 주소입니다. 그들이있을 때 그들은 평등하지 않을 것입니다.
연산자 ==에 대한 주소를 사용하는 것은 나에게 매우 어리석은 행동처럼 보입니다. 새로운 지식이 발견되면 다른 사람들을 위해 여기를 편집하고 계속해서 boost mailing list에 대해 호언 장담 할 것입니다. 지금은
, 동적으로 나도 높일 수 정적으로 연결할 때 그러나,이 작동하지 않습니다
//--------------------------------------------------------------------------------------------------
std::string ClientSocketASIO::ErrorCodeToString(const boost::system::error_code & errorCode)
{
std::ostringstream debugMsg;
debugMsg << " Error Category: " << errorCode.category().name() << ". "
<< " Error Message: " << errorCode.message() << ". ";
// IMPORTANT - These comparisons only work if you dynamically link boost libraries
// Because boost chose to implement boost::system::error_category::operator == by comparing addresses
// The addresses are different in one library and the other when statically linking.
//
// We use make_error_code macro to make the correct category as well as error code value.
// Error code value is not unique and can be duplicated in more than one category.
if (errorCode == make_error_code(boost::asio::error::connection_refused))
{
debugMsg << ". Connection Refused";
}
else if (errorCode == make_error_code(boost::asio::error::eof))
{
debugMsg << ". Server has disconnected.";
}
else
{
debugMsg << ". boost::system::error_code has not been mapped to a meaningful message.";
}
return debugMsg.str();
}
형태로 연결하고 사용하고 있습니다. boost :: system :: error_code를 올바르게 비교하고 기대되는 결과를 얻는 방법에 대한 제안이 있으면 더 자세히 알려주십시오.
그냥 메시지를 원하면'errorCode.message()'를 호출하면됩니다. 이것은 적절한 메시지를 줄 것입니다. 오류의 종류를 이해하려면'value()'를 사용하십시오. 나는 왜 비교가 실패하는지 알지 못한다.'operator =='는 포인터를 검사하도록 정의된다. (오류 코드 시스템은 정적 인 범주의 인스턴스를 사용한다.) 아마도'errorCode.category()'의 주소를 검사 할 수 있고, 'boost :: asio :: error :: misc_category'를 사용하여 실제로 같은지 확인하십시오. – Nim
메시지에 내장하고 싶지 않습니다. 내 품질 보증 팀이 내 기록을 읽을 때 이해할 수있는 자체 메시지를 작성하려고합니다. Joe Bob 테스터는 "파일 끝"의 의미를 알지 못합니다. –
debugMsg = "오류 범주 : asio.misc 오류 메시지 : 파일 끝입니다." & (errorCode.category()) = 0x016e3768. & (boost :: asio :: error :: misc_category) = & 0x536c1250 –