PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/boost/cgi/fcgi/error.hpp

http://github.com/darrengarvey/cgi
C++ Header | 173 lines | 95 code | 36 blank | 42 comment | 0 complexity | f577b4fd4da6120820bfa5ca3603bb0a MD5 | raw file
  1. // -- error.hpp --
  2. //
  3. // Copyright (c) Darren Garvey 2007.
  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. // FastCGI errors are defined in here.
  12. //
  13. ////////////////////////////////////////////////////////////////
  14. #ifndef BOOST_FCGI_ERROR_HPP_INCLUDED__
  15. #define BOOST_FCGI_ERROR_HPP_INCLUDED__
  16. #include <string>
  17. #include <boost/system/error_code.hpp>
  18. BOOST_CGI_NAMESPACE_BEGIN
  19. namespace fcgi {
  20. namespace error {
  21. enum fcgi_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. // **FIXME**
  54. broken_pipe,
  55. // **FIXME**
  56. bad_read,
  57. // **FIXME**
  58. bad_write,
  59. // A client wasn't able to open.
  60. client_not_open,
  61. // Multiplexing connections are not yet supported.
  62. // (I have no access to a server that supports it)
  63. multiplexing_not_supported,
  64. // The client has already been closed.
  65. already_closed,
  66. // An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).
  67. //empty_packet_read,
  68. // End of File (read zero bytes)
  69. eof
  70. };
  71. namespace detail {
  72. class fcgi_category
  73. : public boost::system::error_category
  74. {
  75. public:
  76. const char* name() const BOOST_NOEXCEPT { return "fcgi_error"; }
  77. std::string message(int e) const
  78. {
  79. switch(e)
  80. {
  81. case client_closed:
  82. return "You are trying to read from or write to a closed client.";
  83. case multiplexed_request_incoming:
  84. return "A new request is pending on this connection (ie. it is "
  85. "multiplexed). This isn't handled for now. **FIXME**";
  86. case accepting_on_an_open_request:
  87. return "You called async_accept before closing a request.";
  88. case already_closed:
  89. return "The client has already been closed.";
  90. case multiplexing_not_supported:
  91. return "Multiplexing connections are not yet fully supported.";
  92. case unable_to_duplicate_handle:
  93. return "A call to DuplicateHandle failed while trying to duplicate the FastCGI HANDLE.";
  94. case failed_to_redirect_stdin:
  95. return "A call to SetStdHandle failed while trying to redirect the FastCGI HANDLE.";
  96. case unsupported_handle_type:
  97. return "An unsupported connection type was used to communicate with the FastCGI application.";
  98. //case empty_packet_read:
  99. // return "An empty FastCGI packet was read (eg. STDIN or GET_PARAM data has been read).";
  100. default:
  101. return "An unknown FastCGI error occurred.";
  102. }
  103. }
  104. };
  105. } // namespace detail
  106. inline const boost::system::error_category& get_fcgi_category()
  107. {
  108. static detail::fcgi_category instance;
  109. return instance;
  110. }
  111. static const boost::system::error_category& fcgi_category
  112. = ::BOOST_CGI_NAMESPACE::fcgi::error::get_fcgi_category();
  113. } // namespace error
  114. } // namespace fcgi
  115. BOOST_CGI_NAMESPACE_END
  116. namespace boost {
  117. namespace system {
  118. template<> struct is_error_code_enum<
  119. ::BOOST_CGI_NAMESPACE::fcgi::error::fcgi_errors
  120. >
  121. {
  122. BOOST_STATIC_CONSTANT(bool, value = true);
  123. };
  124. } // namespace system
  125. } // namespace boost
  126. BOOST_CGI_NAMESPACE_BEGIN
  127. namespace fcgi {
  128. namespace error {
  129. inline boost::system::error_code make_error_code(fcgi_errors e)
  130. {
  131. return boost::system::error_code(
  132. static_cast<int>(e), get_fcgi_category());
  133. }
  134. } // namespace error
  135. } // namespace fcgi
  136. BOOST_CGI_NAMESPACE_END
  137. #endif // BOOST_FCGI_ERROR_HPP_INCLUDED__