~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/impl/error_code.ipp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// error_code.ipp
 
3
// ~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 
6
//
 
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)
 
9
//
 
10
 
 
11
#ifndef ASIO_ERROR_CODE_IPP
 
12
#define ASIO_ERROR_CODE_IPP
 
13
 
 
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 
15
# pragma once
 
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 
17
 
 
18
#include "asio/detail/push_options.hpp"
 
19
 
 
20
#include "asio/detail/push_options.hpp"
 
21
#include <boost/config.hpp>
 
22
#include <cerrno>
 
23
#include <cstring>
 
24
#include "asio/detail/pop_options.hpp"
 
25
 
 
26
#include "asio/error.hpp"
 
27
#include "asio/detail/local_free_on_block_exit.hpp"
 
28
#include "asio/detail/socket_types.hpp"
 
29
 
 
30
namespace asio {
 
31
 
 
32
inline std::string error_code::message() const
 
33
{
 
34
  if (*this == error::already_open)
 
35
    return "Already open.";
 
36
  if (*this == error::not_found)
 
37
    return "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())
 
41
    return "SSL error.";
 
42
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
 
43
  value_type value = value_;
 
44
  if (category() != error::get_system_category() && *this != error::eof)
 
45
    return "asio error";
 
46
  if (*this == error::eof)
 
47
    value = ERROR_HANDLE_EOF;
 
48
  char* msg = 0;
 
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')
 
55
    msg[--length] = '\0';
 
56
  if (length && msg[length - 1] == '\r')
 
57
    msg[--length] = '\0';
 
58
  if (length)
 
59
    return msg;
 
60
  else
 
61
    return "asio error";
 
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.";
 
75
#if !defined(__sun)
 
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())
 
84
    return "asio error";
 
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__)
 
90
  char buf[256] = "";
 
91
  strerror_r(value_, buf, sizeof(buf));
 
92
  return buf;
 
93
#else
 
94
  char buf[256] = "";
 
95
  return strerror_r(value_, buf, sizeof(buf));
 
96
#endif
 
97
#endif // defined(BOOST_WINDOWS)
 
98
}
 
99
 
 
100
} // namespace asio
 
101
 
 
102
#include "asio/detail/pop_options.hpp"
 
103
 
 
104
#endif // ASIO_ERROR_CODE_IPP