00001 #ifndef SENTRY_SUE_TCPS_HPP 00002 #define SENTRY_SUE_TCPS_HPP 00003 00004 #include "sue_sel.hpp" 00005 #include "sue_inet.hpp" 00006 00007 struct sockaddr_in; 00008 00009 class SUETcpServerSession; 00010 00012 00029 class SUETcpServer : private SUEFdHandler { 00031 int port; 00033 char *ipaddr; 00035 int mainfd; 00037 struct SessionsListItem { 00038 SUETcpServerSession *sess; 00039 SessionsListItem *next; 00040 } *sessions; 00041 00042 struct sockaddr_in *acceptedsockaddr; 00043 00044 protected: // For overriden SpawnSession 00046 SUEEventSelector *selector; 00047 private: 00049 virtual void FdHandle(bool a_r, bool a_w, bool a_ex); 00050 public: 00052 00061 SUETcpServer(const char *a_ip, int a_port); 00063 virtual ~SUETcpServer(); 00065 00074 bool Up(SUEEventSelector *a_selector); 00076 00080 void Down(); 00081 00083 unsigned long GetIpOfLastAccepted() const; 00084 00086 00093 void NotifySessionDown(SUETcpServerSession* sess); 00094 00095 00096 protected: 00098 00112 virtual SUETcpServerSession* SpawnSession(int newsessionfd) = 0; 00113 }; 00114 00116 00130 class SUETcpServerSession : public SUEInetDuplexSession { 00131 friend class SUETcpServer; 00133 SUETcpServer *server; 00134 00135 protected: 00137 00147 SUETcpServerSession(int a_fd, int a_timeout, 00148 SUEEventSelector *a_selector, 00149 SUETcpServer *a_server, 00150 const char *a_greeting = 0); 00152 00155 virtual ~SUETcpServerSession(); 00156 00157 private: 00159 00167 virtual void ShutdownHook(); 00168 public: 00169 virtual void HandleNewInput() = 0; 00170 00171 //virtual void HandleSessionTimeout(); 00172 //virtual void HandleRemoteClosing(); 00173 //virtual void HandleReadError(); 00174 00175 virtual void TcpServerSessionShutdownHook() {} 00176 }; 00177 00178 #endif