fhq-server  v0.2.33
Documentation for fhq-server. FreeHackQuest is an open source platform for competitions of computer security.
wsjcpp_light_web_server.h
Go to the documentation of this file.
1 #ifndef WSJCPP_LIGHT_WEB_SERVER_H
2 #define WSJCPP_LIGHT_WEB_SERVER_H
3 
4 #include <string>
5 #include <sys/socket.h>
6 #include <arpa/inet.h>
7 
11 
12 // ---------------------------------------------------------------------
13 
15  public:
16  WsjcppLightWebHttpHandlerBase(const std::string &sName);
17  const std::string &name();
18  virtual bool canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) = 0;
19  virtual bool handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest) = 0;
20 
21  private:
22  std::string m_sName;
23 };
24 
25 // ---------------------------------------------------------------------
26 
28  public:
29 
31  const std::string &sName,
33  std::vector<WsjcppLightWebHttpHandlerBase *> *pVHandlers
34  );
35 
36  void start();
37  void stop();
38  void run();
39 
40  private:
41  bool handle(WsjcppLightWebHttpRequest *pRequest);
42  std::string TAG;
43  std::string m_sName;
45  std::vector<WsjcppLightWebHttpHandlerBase *> *m_pVHandlers;
46  bool m_bStop;
47  bool m_bStopped;
48  pthread_t m_serverThread;
49 };
50 
51 // ---------------------------------------------------------------------
52 
54  public:
55 
57  void setPort(int nPort);
58  void setMaxWorkers(int nMaxWorkers);
59  void startSync();
60  void start();
61  void stop();
62  void addHandler(WsjcppLightWebHttpHandlerBase *pHandler);
63 
64  private:
65  void checkAndRestartWorkers();
66  void stopAndRemoveWorkers();
67  std::string readAddress(int nSockFd);
68  std::string TAG;
70  bool m_bStop;
71 
73  int m_nPort;
74  std::vector<WsjcppLightWebHttpHandlerBase *> *m_pVHandlers;
75  std::vector<WsjcppLightWebHttpThreadWorker *> m_vWorkers;
76 
77  int m_nSockFd;
78  struct sockaddr_in m_serverAddress;
79  pthread_t m_serverThread;
80 };
81 
82 #endif // WSJCPP_LIGHT_WEB_SERVER_H
83 
84 
int m_nPort
Definition: wsjcpp_light_web_server.h:73
Definition: wsjcpp_light_web_server.h:53
std::string TAG
Definition: wsjcpp_light_web_server.h:68
WsjcppLightWebDequeHttpRequests * m_pDeque
Definition: wsjcpp_light_web_server.h:69
Definition: wsjcpp_light_web_deque_http_requests.h:12
WsjcppLightWebHttpHandlerBase(const std::string &sName)
Definition: wsjcpp_light_web_server.cpp:9
std::vector< WsjcppLightWebHttpHandlerBase * > * m_pVHandlers
Definition: wsjcpp_light_web_server.h:45
Definition: wsjcpp_light_web_http_request.h:22
pthread_t m_serverThread
Definition: wsjcpp_light_web_server.h:48
Definition: wsjcpp_light_web_server.h:14
std::vector< WsjcppLightWebHttpHandlerBase * > * m_pVHandlers
Definition: wsjcpp_light_web_server.h:74
virtual bool canHandle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest)=0
const std::string & name()
Definition: wsjcpp_light_web_server.cpp:15
int m_nSockFd
Definition: wsjcpp_light_web_server.h:77
Definition: wsjcpp_light_web_server.h:27
std::string m_sName
Definition: wsjcpp_light_web_server.h:43
std::string TAG
Definition: wsjcpp_light_web_server.h:42
std::vector< WsjcppLightWebHttpThreadWorker * > m_vWorkers
Definition: wsjcpp_light_web_server.h:75
int m_nMaxWorkers
Definition: wsjcpp_light_web_server.h:72
WsjcppLightWebDequeHttpRequests * m_pDeque
Definition: wsjcpp_light_web_server.h:44
bool m_bStop
Definition: wsjcpp_light_web_server.h:46
bool m_bStop
Definition: wsjcpp_light_web_server.h:70
virtual bool handle(const std::string &sWorkerId, WsjcppLightWebHttpRequest *pRequest)=0
bool m_bStopped
Definition: wsjcpp_light_web_server.h:47
pthread_t m_serverThread
Definition: wsjcpp_light_web_server.h:79
std::string m_sName
Definition: wsjcpp_light_web_server.h:22