EHS Embedded HTTP Server  1.5.1.0
ehsserver.h
1 /* $Id: ehsserver.h 81 2012-03-20 12:03:05Z felfert $
2  *
3  * EHS is a library for embedding HTTP(S) support into a C++ application
4  *
5  * Copyright (C) 2004 Zachary J. Hansen
6  *
7  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * This can be found in the 'COPYING' file.
23  *
24  */
25 
26 #ifndef _EHSSERVER_H_
27 #define _EHSSERVER_H_
28 
34 class EHSServer {
35 
36  private:
37 
38  EHSServer(const EHSServer &);
39 
40  EHSServer & operator=(const EHSServer &);
41 
42  public:
43 
49  EHSServer(EHS *ipoTopLevelEHS);
50 
52  virtual ~EHSServer();
53 
59 
65  void HandleData(int timeout, ehs_threadid_t tid = 0);
66 
69  SERVERRUNNING_INVALID = 0,
70  SERVERRUNNING_NOTRUNNING,
71  SERVERRUNNING_SINGLETHREADED,
72  SERVERRUNNING_THREADPOOL,
73  SERVERRUNNING_ONETHREADPERREQUEST,
74  SERVERRUNNING_SHOULDTERMINATE
75  };
76 
81  ServerRunningStatus RunningStatus() const { return m_nServerRunningStatus; }
82 
87  bool AcceptedNewConnection() const { return m_bAcceptedNewConnection; }
88 
90  int RequestsPending() const { return m_nRequestsPending; }
91 
97  static void *PthreadHandleData_ThreadedStub(void *ipData);
98 
99  private:
100 
102  HttpRequest *GetNextRequest();
103 
105  void IncrementRequestsPending() { m_nRequestsPending++; }
106 
111  void RemoveEHSConnection(EHSConnection *ipoEHSConnection);
112 
115  void HandleData_Threaded();
116 
120  void ClearIdleConnections();
121 
123  void CheckClientSockets();
124 
126  void CheckAcceptSocket();
127 
129  int CreateFdSet();
130 
134  void RemoveFinishedConnections();
135 
137  ServerRunningStatus m_nServerRunningStatus;
138 
140  EHS * m_poTopLevelEHS;
141 
143  bool m_bAcceptedNewConnection;
144 
146  pthread_mutex_t m_oMutex;
147 
149  pthread_cond_t m_oDoneAccepting;
150 
152  int m_nRequestsPending;
153 
155  bool m_bAccepting;
156 
158  std::string m_sServerName;
159 
161  fd_set m_oReadFds;
162 
164  EHSConnectionList m_oEHSConnectionList;
165 
167  NetworkAbstraction * m_poNetworkAbstraction;
168 
170  ehs_threadid_t m_nAcceptThreadId;
171 
173  int m_nIdleTimeout;
174 
176  int m_nThreads;
177 
179  CurrentRequestMap m_oCurrentRequest;
180 
182  pthread_attr_t m_oThreadAttr;
183 
184  friend class EHSConnection;
185 };
186 
187 #endif // _EHSSERVER_H_
EHSConnection abstracts the concept of a connection to an EHS application.
Definition: ehsconnection.h:40
EHSServer contains all the network related services for EHS.
Definition: ehsserver.h:34
ServerRunningStatus RunningStatus() const
Retrieves the current running status of this instance.
Definition: ehsserver.h:81
void EndServerThread()
Stops the server.
EHSServer(EHS *ipoTopLevelEHS)
Constucts a new instance.
bool AcceptedNewConnection() const
Retrieve accept status.
Definition: ehsserver.h:87
ServerRunningStatus
Enumeration on the current running status of the EHSServer.
Definition: ehsserver.h:68
static void * PthreadHandleData_ThreadedStub(void *ipData)
Static pthread worker.
virtual ~EHSServer()
Destructor.
int RequestsPending() const
Returns number of requests pending.
Definition: ehsserver.h:90
void HandleData(int timeout, ehs_threadid_t tid=0)
Main method that deals with client connections and getting data.
EHS provides HTTP server functionality to a child class.
Definition: ehs.h:147
This class represents a clients HTTP request.
Definition: httprequest.h:51
Abstracts different socket types.