PageRenderTime 110ms CodeModel.GetById 50ms app.highlight 9ms RepoModel.GetById 19ms app.codeStats 1ms

/boost/cgi/scgi/error.hpp

http://github.com/darrengarvey/cgi
C++ Header | 180 lines | 99 code | 38 blank | 43 comment | 0 complexity | 407b42e1b95daae481f20df749bbf53e MD5 | raw file
  1//                     -- error.hpp --
  2//
  3//            Copyright (c) Darren Garvey 2010.
  4// Distributed under the Boost Software License, Version 1.0.
  5//    (See accompanying file LICENSE_1_0.txt or copy at
  6//          http://www.boost.org/LICENSE_1_0.txt)
  7//
  8// Abstract:
  9// ---------
 10//
 11// SCGI errors are defined in here.
 12//
 13////////////////////////////////////////////////////////////////
 14#ifndef BOOST_SCGI_ERROR_HPP_INCLUDED__
 15#define BOOST_SCGI_ERROR_HPP_INCLUDED__
 16
 17#include <string>
 18#include <boost/system/error_code.hpp>
 19
 20BOOST_CGI_NAMESPACE_BEGIN
 21 namespace scgi {
 22  namespace error {
 23
 24enum scgi_errors
 25{
 26  bad_header_type = 1,
 27
 28  /// A packet arrived for a request id that doesn't exist and the 
 29  /// packet wasn't a BEGIN_REQUEST record.
 30  bad_request_id,
 31
 32  /// When trying to write a packet, the client::write_some() call didn't
 33  // transmit enough data before returning.
 34  couldnt_write_complete_packet,
 35
 36  // Tried to read/write from/to the client associated to a request when it
 37  // was closed.
 38  client_closed,
 39
 40  // Self-explanatory (not much a user can do about this though).
 41  abort_request_record_recieved_for_invalid_request,
 42
 43  // For now a user has to recognise this error and construct a request
 44  // themselves. This is an ugly hack.
 45  multiplexed_request_incoming,
 46
 47  // A begin_request packet has come in with an existing request id.
 48  duplicate_request,
 49
 50  // Calling async_accept on a request that hasn't been closed isn't
 51  // allowed.
 52  accepting_on_an_open_request,
 53
 54  invalid_socket,
 55
 56  // On Windows, attempting to call DuplicateHandle on STDIN failed.
 57  unable_to_duplicate_handle,
 58
 59  // On Windows, a call to SetStdHandle failed.
 60  failed_to_redirect_stdin,
 61
 62  // On Windows, TCP connections aren't supported.
 63  unsupported_handle_type,
 64
 65  // The CONTENT_TYPE for form data wasn't recognised.
 66  invalid_form_type,
 67
 68  // Used in basic_connection<tags::stdio>
 69  broken_pipe,
 70
 71  // An invalid request was received.
 72  invalid_request,
 73
 74  // **FIXME**
 75  bad_read,
 76
 77  // **FIXME**
 78  bad_write,
 79
 80  // A client wasn't able to open.
 81  client_not_open,
 82  
 83  // Multiplexing connections are not yet supported.
 84  // (I have no access to a server that supports it)
 85  multiplexing_not_supported,
 86  
 87  // The client has already been closed.
 88  already_closed,
 89
 90  // There is no such thing as 'default initialisation' with SCGI.
 91  no_default_init,
 92  
 93  // An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).
 94  //empty_packet_read,
 95  
 96  // End of File (read zero bytes)
 97  eof
 98};
 99
100  namespace detail {
101
102class scgi_category
103  : public boost::system::error_category
104{
105public:
106  const char* name() const BOOST_NOEXCEPT { return "scgi_error"; }
107  std::string message(int e) const
108  {
109    switch(e)
110    {
111    case client_closed:
112      return "You are trying to read from or write to a closed client.";
113    case multiplexed_request_incoming:
114      return "A new request is pending on this connection (ie. it is "
115             "multiplexed). This isn't handled for now. **FIXME**";
116    case accepting_on_an_open_request:
117      return "You called async_accept before closing a request.";
118    case already_closed:
119      return "The client has already been closed.";
120    case invalid_request:
121      return "An invalid request was received.";
122    case multiplexing_not_supported:
123      return "Multiplexing connections are not yet fully supported.";
124    case unable_to_duplicate_handle:
125      return "A call to DuplicateHandle failed while trying to duplicate the FastCGI HANDLE.";
126    case failed_to_redirect_stdin:
127      return "A call to SetStdHandle failed while trying to redirect the FastCGI HANDLE.";
128    case unsupported_handle_type:
129      return "An unsupported connection type was used to communicate with the FastCGI application.";
130    //case empty_packet_read:
131    //  return "An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).";
132    default:
133      return "An unknown FastCGI error occurred.";
134    }
135  }
136};
137
138  } // namespace detail
139
140inline const boost::system::error_category& get_scgi_category()
141{
142  static detail::scgi_category instance;
143  return instance;
144}
145
146static const boost::system::error_category& scgi_category
147  = ::BOOST_CGI_NAMESPACE::scgi::error::get_scgi_category();
148
149  } // namespace error
150 } // namespace scgi
151BOOST_CGI_NAMESPACE_END
152
153namespace boost {
154  namespace system {
155
156    template<> struct is_error_code_enum<
157        ::BOOST_CGI_NAMESPACE::scgi::error::scgi_errors
158      >
159    {
160      BOOST_STATIC_CONSTANT(bool, value = true);
161    };
162
163  } // namespace system
164} // namespace boost
165
166BOOST_CGI_NAMESPACE_BEGIN
167 namespace scgi {
168  namespace error {
169  
170    inline boost::system::error_code make_error_code(scgi_errors e)
171    {
172      return boost::system::error_code(
173          static_cast<int>(e), get_scgi_category());
174    }
175
176  } // namespace error
177 } // namespace scgi
178BOOST_CGI_NAMESPACE_END
179
180#endif // BOOST_SCGI_ERROR_HPP_INCLUDED__