00001 00002 /*************************************************************************** 00003 * Copyright (C) 2007 Eddie * 00004 * * 00005 * This file is part of fastcgi++. * 00006 * * 00007 * fastcgi++ is free software: you can redistribute it and/or modify it * 00008 * under the terms of the GNU Lesser General Public License as published * 00009 * by the Free Software Foundation, either version 3 of the License, or (at * 00010 * your option) any later version. * 00011 * * 00012 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT * 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * 00015 * License for more details. * 00016 * * 00017 * You should have received a copy of the GNU Lesser General Public License * 00018 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. * 00019 ****************************************************************************/ 00020 00021 00022 #ifndef EXCEPTIONS_HPP 00023 #define EXCEPTIONS_HPP 00024 00025 #include <exception> 00026 #include <string> 00027 00028 #include <fastcgi++/protocol.hpp> 00029 00031 namespace Fastcgipp 00032 { 00034 namespace Exceptions 00035 { 00037 class Exception: public std::exception 00038 { 00039 public: 00040 virtual const char* what() const throw() =0; 00041 ~Exception() throw() {} 00042 }; 00043 00045 class Request: public Exception 00046 { 00047 public: 00049 00052 Request(Protocol::FullId id_): id(id_) { } 00053 ~Request() throw() {} 00054 00055 virtual const char* what() const throw() =0; 00056 Protocol::FullId getId() const throw() { return id; } 00057 protected: 00059 Protocol::FullId id; 00060 }; 00061 00063 class Param: public Request 00064 { 00065 public: 00067 00070 Param(Protocol::FullId id_); 00071 ~Param() throw() {} 00072 virtual const char* what() const throw() { return msg.c_str(); } 00073 private: 00075 std::string msg; 00076 }; 00077 00079 class Stream: public Request 00080 { 00081 public: 00083 00086 Stream(Protocol::FullId id_); 00087 ~Stream() throw() {} 00088 virtual const char* what() const throw() { return msg.c_str(); } 00089 private: 00091 std::string msg; 00092 }; 00093 00095 class RecordOutOfOrder: public Request 00096 { 00097 public: 00099 00104 RecordOutOfOrder(Protocol::FullId id_, Protocol::RecordType expectedRecord_, Protocol::RecordType recievedRecord_); 00105 ~RecordOutOfOrder() throw() {} 00106 virtual const char* what() const throw() { return msg.c_str(); } 00107 Protocol::RecordType getExpectedRecord() const throw() { return expectedRecord; } 00108 Protocol::RecordType getRecievedRecord() const throw() { return recievedRecord; } 00109 private: 00111 Protocol::RecordType expectedRecord; 00113 Protocol::RecordType recievedRecord; 00115 std::string msg; 00116 }; 00117 00119 class Socket: public Exception 00120 { 00121 public: 00123 00127 Socket(int fd_, int erno_): fd(fd_), erno(erno_) { } 00128 ~Socket() throw() {} 00129 virtual const char* what() const throw() =0; 00130 int getFd() const throw() { return fd; } 00131 int getErrno() const throw() { return erno; } 00132 protected: 00134 int fd; 00136 int erno; 00137 }; 00138 00140 class SocketWrite: public Socket 00141 { 00142 public: 00144 00148 SocketWrite(int fd_, int erno_); 00149 ~SocketWrite() throw() {} 00150 virtual const char* what() const throw() { return msg.c_str(); } 00151 private: 00153 std::string msg; 00154 }; 00155 00157 class SocketRead: public Socket 00158 { 00159 public: 00161 00165 SocketRead(int fd_, int erno_); 00166 ~SocketRead() throw() {} 00167 virtual const char* what() const throw() { return msg.c_str(); } 00168 private: 00170 std::string msg; 00171 }; 00172 00174 class Poll: public Exception 00175 { 00176 public: 00178 00181 Poll(int erno_); 00182 ~Poll() throw() {} 00183 virtual const char* what() const throw() { return msg.c_str(); } 00184 int getErno() const throw() { return erno; } 00185 private: 00187 int erno; 00189 std::string msg; 00190 }; 00191 } 00192 } 00193 00194 #endif