5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef ASIO_ERROR_CODE_IPP
12
#define ASIO_ERROR_CODE_IPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
24
#include "asio/detail/pop_options.hpp"
26
#include "asio/error.hpp"
27
#include "asio/detail/local_free_on_block_exit.hpp"
28
#include "asio/detail/socket_types.hpp"
32
inline std::string error_code::message() const
34
if (*this == error::already_open)
35
return "Already open.";
36
if (*this == error::not_found)
38
if (*this == error::fd_set_failure)
39
return "The descriptor does not fit into the select call's fd_set.";
40
if (category_ == error::get_ssl_category())
42
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
43
value_type value = value_;
44
if (category() != error::get_system_category() && *this != error::eof)
46
if (*this == error::eof)
47
value = ERROR_HANDLE_EOF;
49
DWORD length = ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
50
| FORMAT_MESSAGE_FROM_SYSTEM
51
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
52
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, 0);
53
detail::local_free_on_block_exit local_free_obj(msg);
54
if (length && msg[length - 1] == '\n')
56
if (length && msg[length - 1] == '\r')
62
#else // defined(BOOST_WINDOWS)
63
if (*this == error::eof)
64
return "End of file.";
65
if (*this == error::host_not_found)
66
return "Host not found (authoritative).";
67
if (*this == error::host_not_found_try_again)
68
return "Host not found (non-authoritative), try again later.";
69
if (*this == error::no_recovery)
70
return "A non-recoverable error occurred during database lookup.";
71
if (*this == error::no_data)
72
return "The query is valid, but it does not have associated data.";
73
if (*this == error::not_found)
74
return "Element not found.";
76
if (*this == error::operation_aborted)
77
return "Operation aborted.";
78
#endif // !defined(__sun)
79
if (*this == error::service_not_found)
80
return "Service not found.";
81
if (*this == error::socket_type_not_supported)
82
return "Socket type not supported.";
83
if (category() != error::get_system_category())
85
#if defined(__sun) || defined(__QNX__)
86
return strerror(value_);
87
#elif defined(__MACH__) && defined(__APPLE__) \
88
|| defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
89
|| defined(_AIX) || defined(__hpux) || defined(__osf__)
91
strerror_r(value_, buf, sizeof(buf));
95
return strerror_r(value_, buf, sizeof(buf));
97
#endif // defined(BOOST_WINDOWS)
102
#include "asio/detail/pop_options.hpp"
104
#endif // ASIO_ERROR_CODE_IPP