PageRenderTime 4354ms CodeModel.GetById 54ms RepoModel.GetById 41ms app.codeStats 244ms

/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. #include <string>
  17. #include <boost/system/error_code.hpp>
  18. BOOST_CGI_NAMESPACE_BEGIN
  19. namespace scgi {
  20. namespace error {
  21. enum scgi_errors
  22. {
  23. bad_header_type = 1,
  24. /// A packet arrived for a request id that doesn't exist and the
  25. /// packet wasn't a BEGIN_REQUEST record.
  26. bad_request_id,
  27. /// When trying to write a packet, the client::write_some() call didn't
  28. // transmit enough data before returning.
  29. couldnt_write_complete_packet,
  30. // Tried to read/write from/to the client associated to a request when it
  31. // was closed.
  32. client_closed,
  33. // Self-explanatory (not much a user can do about this though).
  34. abort_request_record_recieved_for_invalid_request,
  35. // For now a user has to recognise this error and construct a request
  36. // themselves. This is an ugly hack.
  37. multiplexed_request_incoming,
  38. // A begin_request packet has come in with an existing request id.
  39. duplicate_request,
  40. // Calling async_accept on a request that hasn't been closed isn't
  41. // allowed.
  42. accepting_on_an_open_request,
  43. invalid_socket,
  44. // On Windows, attempting to call DuplicateHandle on STDIN failed.
  45. unable_to_duplicate_handle,
  46. // On Windows, a call to SetStdHandle failed.
  47. failed_to_redirect_stdin,
  48. // On Windows, TCP connections aren't supported.
  49. unsupported_handle_type,
  50. // The CONTENT_TYPE for form data wasn't recognised.
  51. invalid_form_type,
  52. // Used in basic_connection<tags::stdio>
  53. broken_pipe,
  54. // An invalid request was received.
  55. invalid_request,
  56. // **FIXME**
  57. bad_read,
  58. // **FIXME**
  59. bad_write,
  60. // A client wasn't able to open.
  61. client_not_open,
  62. // Multiplexing connections are not yet supported.
  63. // (I have no access to a server that supports it)
  64. multiplexing_not_supported,
  65. // The client has already been closed.
  66. already_closed,
  67. // There is no such thing as 'default initialisation' with SCGI.
  68. no_default_init,
  69. // An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).
  70. //empty_packet_read,
  71. // End of File (read zero bytes)
  72. eof
  73. };
  74. namespace detail {
  75. class scgi_category
  76. : public boost::system::error_category
  77. {
  78. public:
  79. const char* name() const BOOST_NOEXCEPT { return "scgi_error"; }
  80. std::string message(int e) const
  81. {
  82. switch(e)
  83. {
  84. case client_closed:
  85. return "You are trying to read from or write to a closed client.";
  86. case multiplexed_request_incoming:
  87. return "A new request is pending on this connection (ie. it is "
  88. "multiplexed). This isn't handled for now. **FIXME**";
  89. case accepting_on_an_open_request:
  90. return "You called async_accept before closing a request.";
  91. case already_closed:
  92. return "The client has already been closed.";
  93. case invalid_request:
  94. return "An invalid request was received.";
  95. case multiplexing_not_supported:
  96. return "Multiplexing connections are not yet fully supported.";
  97. case unable_to_duplicate_handle:
  98. return "A call to DuplicateHandle failed while trying to duplicate the FastCGI HANDLE.";
  99. case failed_to_redirect_stdin:
  100. return "A call to SetStdHandle failed while trying to redirect the FastCGI HANDLE.";
  101. case unsupported_handle_type:
  102. return "An unsupported connection type was used to communicate with the FastCGI application.";
  103. //case empty_packet_read:
  104. // return "An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).";
  105. default:
  106. return "An unknown FastCGI error occurred.";
  107. }
  108. }
  109. };
  110. } // namespace detail
  111. inline const boost::system::error_category& get_scgi_category()
  112. {
  113. static detail::scgi_category instance;
  114. return instance;
  115. }
  116. static const boost::system::error_category& scgi_category
  117. = ::BOOST_CGI_NAMESPACE::scgi::error::get_scgi_category();
  118. } // namespace error
  119. } // namespace scgi
  120. BOOST_CGI_NAMESPACE_END
  121. namespace boost {
  122. namespace system {
  123. template<> struct is_error_code_enum<
  124. ::BOOST_CGI_NAMESPACE::scgi::error::scgi_errors
  125. >
  126. {
  127. BOOST_STATIC_CONSTANT(bool, value = true);
  128. };
  129. } // namespace system
  130. } // namespace boost
  131. BOOST_CGI_NAMESPACE_BEGIN
  132. namespace scgi {
  133. namespace error {
  134. inline boost::system::error_code make_error_code(scgi_errors e)
  135. {
  136. return boost::system::error_code(
  137. static_cast<int>(e), get_scgi_category());
  138. }
  139. } // namespace error
  140. } // namespace scgi
  141. BOOST_CGI_NAMESPACE_END
  142. #endif // BOOST_SCGI_ERROR_HPP_INCLUDED__