00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_ERROR_CODE_IPP
00012 #define ASIO_ERROR_CODE_IPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/config.hpp>
00022 #include <cerrno>
00023 #include <cstring>
00024 #include "asio/detail/pop_options.hpp"
00025
00026 #include "asio/error.hpp"
00027 #include "asio/detail/local_free_on_block_exit.hpp"
00028 #include "asio/detail/socket_types.hpp"
00029
00030 namespace asio {
00031
00032 inline std::string error_code::message() const
00033 {
00034 if (*this == error::already_open)
00035 return "Already open.";
00036 if (*this == error::not_found)
00037 return "Not found.";
00038 if (category_ == ssl_ecat)
00039 return "SSL error.";
00040 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
00041 value_type value = value_;
00042 if (*this == error::eof)
00043 value = ERROR_HANDLE_EOF;
00044 char* msg = 0;
00045 DWORD length = ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
00046 | FORMAT_MESSAGE_FROM_SYSTEM
00047 | FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
00048 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, 0);
00049 detail::local_free_on_block_exit local_free_obj(msg);
00050 if (length && msg[length - 1] == '\n')
00051 msg[--length] = '\0';
00052 if (length && msg[length - 1] == '\r')
00053 msg[--length] = '\0';
00054 if (length)
00055 return msg;
00056 else
00057 return "asio error";
00058 #else // defined(BOOST_WINDOWS)
00059 if (*this == error::eof)
00060 return "End of file.";
00061 if (*this == error::host_not_found)
00062 return "Host not found (authoritative).";
00063 if (*this == error::host_not_found_try_again)
00064 return "Host not found (non-authoritative), try again later.";
00065 if (*this == error::no_recovery)
00066 return "A non-recoverable error occurred during database lookup.";
00067 if (*this == error::no_data)
00068 return "The query is valid, but it does not have associated data.";
00069 if (*this == error::not_found)
00070 return "Element not found.";
00071 #if !defined(__sun)
00072 if (*this == error::operation_aborted)
00073 return "Operation aborted.";
00074 #endif // !defined(__sun)
00075 if (*this == error::service_not_found)
00076 return "Service not found.";
00077 if (*this == error::socket_type_not_supported)
00078 return "Socket type not supported.";
00079 #if defined(__sun) || defined(__QNX__)
00080 return strerror(value_);
00081 #elif defined(__MACH__) && defined(__APPLE__) \
00082 || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
00083 || defined(_AIX)
00084 char buf[256] = "";
00085 strerror_r(value_, buf, sizeof(buf));
00086 return buf;
00087 #else
00088 char buf[256] = "";
00089 return strerror_r(value_, buf, sizeof(buf));
00090 #endif
00091 #endif // defined(BOOST_WINDOWS)
00092 }
00093
00094 }
00095
00096 #include "asio/detail/pop_options.hpp"
00097
00098 #endif // ASIO_ERROR_CODE_IPP