1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2010 - 2015, Göteborg Bit Factory.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
23 // http://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26 #ifndef INCLUDED_SERVER
27 #define INCLUDED_SERVER
28 
29 #include <sys/types.h>
30 #include <string>
31 #include <ConfigFile.h>
32 #include <Log.h>
33 
34 class Server
35 {
36 public:
37   Server ();
38   virtual ~Server ();
39   void setHost (const std::string&);
40   void setPort (const std::string&);
41   void setFamily (const std::string&);
42   void setPoolSize (int);
43   void setQueueSize (int);
44   void setDaemon ();
45   void setBlocking ();
46   void setNonBlocking ();
47   void setPidFile (const std::string&);
48   void setLog (Log*);
49   void setConfig (Config*);
50   void setLimit (int);
51   void setCAFile (const std::string&);
52   void setCertFile (const std::string&);
53   void setKeyFile (const std::string&);
54   void setCRLFile (const std::string&);
55   void setLogClients (bool);
56   void start ();
57 
58   void beginServer ();
59 
60   void stats (int&, time_t&, double&);
61 
62   virtual void handler (const std::string&, std::string&) = 0;
63 
64 protected:
65   void daemonize ();
66   void writePidFile ();
67   void removePidFile ();
68   Log* _log;
69   Config* _config;
70   bool _log_clients;
71   std::string _client_address;
72   int _client_port;
73 
74 private:
75   std::string _host;
76   std::string _port;
77   std::string _family;
78   int _pool_size;
79   int _queue_size;
80   bool _daemon;
81   std::string _pid_file;
82   int _request_count;
83   int _limit;
84   std::string _ca_file;
85   std::string _cert_file;
86   std::string _key_file;
87   std::string _crl_file;
88 };
89 
90 #endif
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 
94