Here is a stackoverflow question where it is answered: https://stackoverflow.com/questions/28746372/system-error-categories-and-standard-system-error-codes
errno values are the errors returned by the operating system? Should I use system_category() (which would be wrong on non-Unix-like systems, needing an #ifdef), or should I use generic_category() (which would be wrong on Unix-like systems for non-standard errno values)?"try
{
send(http::request(...));
}
catch(const std::system_error &ex)
{
if(ex.code() == std::errc::broken_pipe)
{
// Do something
}
}
Remember if you're accessing ec.code(), you're doing something wrong 99% of the time.Try comparing ec directly to std::errc::broken_pipe.
asio::error is an enum inside the system_category error number space. It ought to work, depending on whether your STL implementer has mapped the win32 error code ERROR_BROKEN_PIPE to std::errc::broken_pipe (I would have thought that mapping pretty obvious, but there are known incorrect win32 to POSIX error code maps in MSVCRT which cannot be fixed for backwards compatibility reasons).
Try comparing ec directly to std::errc::broken_pipe. asio::error is an enum inside the system_category error number space.
On Monday, October 17, 2016 at 2:20:36 PM UTC+3, nialldo...@gmail.com wrote:Remember if you're accessing ec.code(), you're doing something wrong 99% of the time.Try comparing ec directly to std::errc::broken_pipe.What? Which "ec"? Do you mean "ex" - compare exception with error condition?
On Monday, October 17, 2016 at 9:15:55 AM UTC+1, Victor Dyachenko wrote:Ok. One simple task. Suppose we have some HTTP C++ library and want to detect situations when the peer unexpectedly closes the channel. On POSIX systems we will have EPIPE on write()/send().try
{
send(http::request(...));
}
catch(const std::system_error &ex)
{
if(ex.code() == std::errc::broken_pipe)
{
// Do something
}
}
Does it look reasonable? Yes, for me. But it doesn't work in practice!
If the HTTP-library uses Asio (even standalone version) you have to check the error condition against the library-specific asio::error::broken_pipe inspite of the error came from the OS.Remember if you're accessing ec.code(), you're doing something wrong 99% of the time.