EHS Embedded HTTP Server  1.5.0.132
ehsserver.h
00001 /* $Id: ehsserver.h 81 2012-03-20 12:03:05Z felfert $
00002  *
00003  * EHS is a library for embedding HTTP(S) support into a C++ application
00004  *
00005  * Copyright (C) 2004 Zachary J. Hansen
00006  *
00007  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
00008  *
00009  *    This library is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License version 2.1 as published by the Free Software Foundation;
00012  *
00013  *    This library is distributed in the hope that it will be useful,
00014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *    Lesser General Public License for more details.
00017  *
00018  *    You should have received a copy of the GNU Lesser General Public
00019  *    License along with this library; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *    This can be found in the 'COPYING' file.
00023  *
00024  */
00025 
00026 #ifndef _EHSSERVER_H_
00027 #define _EHSSERVER_H_
00028 
00034 class EHSServer {
00035 
00036     private:
00037 
00038         EHSServer(const EHSServer &);
00039 
00040         EHSServer & operator=(const EHSServer &);
00041 
00042     public:
00043 
00049         EHSServer(EHS *ipoTopLevelEHS);
00050 
00052         virtual ~EHSServer();
00053 
00058         void EndServerThread();
00059 
00065         void HandleData(int timeout, ehs_threadid_t tid = 0); 
00066 
00068         enum ServerRunningStatus {
00069             SERVERRUNNING_INVALID = 0,
00070             SERVERRUNNING_NOTRUNNING,
00071             SERVERRUNNING_SINGLETHREADED,
00072             SERVERRUNNING_THREADPOOL,
00073             SERVERRUNNING_ONETHREADPERREQUEST,
00074             SERVERRUNNING_SHOULDTERMINATE
00075         };
00076 
00081         ServerRunningStatus RunningStatus() const { return m_nServerRunningStatus; }
00082 
00087         bool AcceptedNewConnection() const { return m_bAcceptedNewConnection; }
00088 
00090         int RequestsPending() const { return m_nRequestsPending; }
00091 
00097         static void *PthreadHandleData_ThreadedStub(void *ipData);
00098 
00099     private:
00100 
00102         HttpRequest *GetNextRequest();
00103 
00105         void IncrementRequestsPending() { m_nRequestsPending++; }
00106 
00111         void RemoveEHSConnection(EHSConnection *ipoEHSConnection);
00112 
00115         void HandleData_Threaded();
00116 
00120         void ClearIdleConnections();
00121 
00123         void CheckClientSockets();
00124 
00126         void CheckAcceptSocket();
00127 
00129         int CreateFdSet();
00130 
00134         void RemoveFinishedConnections();
00135 
00137         ServerRunningStatus m_nServerRunningStatus;
00138 
00140         EHS * m_poTopLevelEHS;
00141 
00143         bool m_bAcceptedNewConnection;
00144 
00146         pthread_mutex_t m_oMutex;
00147 
00149         pthread_cond_t m_oDoneAccepting;
00150 
00152         int m_nRequestsPending;
00153 
00155         bool m_bAccepting;
00156 
00158         std::string m_sServerName;
00159 
00161         fd_set m_oReadFds;
00162 
00164         EHSConnectionList m_oEHSConnectionList;
00165 
00167         NetworkAbstraction * m_poNetworkAbstraction;
00168 
00170         ehs_threadid_t m_nAcceptThreadId;
00171 
00173         int m_nIdleTimeout;
00174 
00176         int m_nThreads;
00177 
00179         CurrentRequestMap m_oCurrentRequest;
00180 
00182         pthread_attr_t m_oThreadAttr;
00183 
00184         friend class EHSConnection;
00185 };
00186 
00187 #endif // _EHSSERVER_H_