cgi /boost/cgi/scgi/error.hpp

Language C/C++ Header Lines 181
MD5 Hash b63e26d71be1beae391c16e61e8e263b Estimated Cost $2,383 (why?)
Repository git://github.com/darrengarvey/cgi.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//                     -- error.hpp --
//
//            Copyright (c) Darren Garvey 2010.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)
//
// Abstract:
// ---------
//
// SCGI errors are defined in here.
//
////////////////////////////////////////////////////////////////
#ifndef BOOST_SCGI_ERROR_HPP_INCLUDED__
#define BOOST_SCGI_ERROR_HPP_INCLUDED__

#include <string>
#include <boost/system/error_code.hpp>

BOOST_CGI_NAMESPACE_BEGIN
 namespace scgi {
  namespace error {

enum scgi_errors
{
  bad_header_type = 1,

  /// A packet arrived for a request id that doesn't exist and the 
  /// packet wasn't a BEGIN_REQUEST record.
  bad_request_id,

  /// When trying to write a packet, the client::write_some() call didn't
  // transmit enough data before returning.
  couldnt_write_complete_packet,

  // Tried to read/write from/to the client associated to a request when it
  // was closed.
  client_closed,

  // Self-explanatory (not much a user can do about this though).
  abort_request_record_recieved_for_invalid_request,

  // For now a user has to recognise this error and construct a request
  // themselves. This is an ugly hack.
  multiplexed_request_incoming,

  // A begin_request packet has come in with an existing request id.
  duplicate_request,

  // Calling async_accept on a request that hasn't been closed isn't
  // allowed.
  accepting_on_an_open_request,

  invalid_socket,

  // On Windows, attempting to call DuplicateHandle on STDIN failed.
  unable_to_duplicate_handle,

  // On Windows, a call to SetStdHandle failed.
  failed_to_redirect_stdin,

  // On Windows, TCP connections aren't supported.
  unsupported_handle_type,

  // The CONTENT_TYPE for form data wasn't recognised.
  invalid_form_type,

  // Used in basic_connection<tags::stdio>
  broken_pipe,

  // An invalid request was received.
  invalid_request,

  // **FIXME**
  bad_read,

  // **FIXME**
  bad_write,

  // A client wasn't able to open.
  client_not_open,
  
  // Multiplexing connections are not yet supported.
  // (I have no access to a server that supports it)
  multiplexing_not_supported,
  
  // The client has already been closed.
  already_closed,

  // There is no such thing as 'default initialisation' with SCGI.
  no_default_init,
  
  // An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).
  //empty_packet_read,
  
  // End of File (read zero bytes)
  eof
};

  namespace detail {

class scgi_category
  : public boost::system::error_category
{
public:
  const char* name() const { return "scgi_error"; }
  std::string message(int e) const
  {
    switch(e)
    {
    case client_closed:
      return "You are trying to read from or write to a closed client.";
    case multiplexed_request_incoming:
      return "A new request is pending on this connection (ie. it is "
             "multiplexed). This isn't handled for now. **FIXME**";
    case accepting_on_an_open_request:
      return "You called async_accept before closing a request.";
    case already_closed:
      return "The client has already been closed.";
    case invalid_request:
      return "An invalid request was received.";
    case multiplexing_not_supported:
      return "Multiplexing connections are not yet fully supported.";
    case unable_to_duplicate_handle:
      return "A call to DuplicateHandle failed while trying to duplicate the FastCGI HANDLE.";
    case failed_to_redirect_stdin:
      return "A call to SetStdHandle failed while trying to redirect the FastCGI HANDLE.";
    case unsupported_handle_type:
      return "An unsupported connection type was used to communicate with the FastCGI application.";
    //case empty_packet_read:
    //  return "An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).";
    default:
      return "An unknown FastCGI error occurred.";
    }
  }
};

  } // namespace detail

inline const boost::system::error_category& get_scgi_category()
{
  static detail::scgi_category instance;
  return instance;
}

static const boost::system::error_category& scgi_category
  = ::BOOST_CGI_NAMESPACE::scgi::error::get_scgi_category();

  } // namespace error
 } // namespace scgi
BOOST_CGI_NAMESPACE_END

namespace boost {
  namespace system {

    template<> struct is_error_code_enum<
        ::BOOST_CGI_NAMESPACE::scgi::error::scgi_errors
      >
    {
      BOOST_STATIC_CONSTANT(bool, value = true);
    };

  } // namespace system
} // namespace boost

BOOST_CGI_NAMESPACE_BEGIN
 namespace scgi {
  namespace error {
  
    inline boost::system::error_code make_error_code(scgi_errors e)
    {
      return boost::system::error_code(
          static_cast<int>(e), get_scgi_category());
    }

  } // namespace error
 } // namespace scgi
BOOST_CGI_NAMESPACE_END

#endif // BOOST_SCGI_ERROR_HPP_INCLUDED__
Back to Top