rasdaman complete source
akgnet_server.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
34 #ifndef AKGNET_SERVER_HH
35 #define AKGNET_SERVER_HH
36 
37 //#### Includes #################################
38 
39 #include "akgnet_socket.hh"
40 #include "akgnet_selector.hh"
41 #include "akgnet_commbuffer.hh"
42 
43 //###############################################
44 
45 
46 namespace akg
47 {
57 class GenericServer
58 {
59 public:
61  GenericServer() throw();
62 
64  virtual ~GenericServer() throw();
65 
66  //*************************
73  virtual bool runServer() throw() =0;
74  //*************************
75 
77  void shouldExit() throw();
78 
80  void setListenPort(int) throw();
81 
83  int getListenPort() throw();
84 
88  void setTimeout(int sec,int milisec) throw();
89 
91  void disableTimeout() throw();
92 
93 protected:
95  bool initListenSocket(int port, bool nonblocking) throw();
96 
100  bool connectNewClient(ServerSocket&) throw();
101 
105  void closeSocket(Socket&) throw();
106 
107  ListenSocket listenSocket;
108  int listenPort;
109 
110  Selector selector;
111 
112  bool exitRequest;
113 
114 private:
116  GenericServer(const GenericServer&);
118  GenericServer& operator=(const GenericServer&);
119 };
120 
121 
132 class BlockingServer : public GenericServer
133 {
134 public:
136  BlockingServer() throw();
138  ~BlockingServer() throw();
139 
143  bool runServer() throw();
144 protected:
145  //************************************************
150  virtual void executeRequest(ServerSocket&) throw() =0;
151 
154  virtual void executeTimeout() throw() =0;
155  //************************************************
156 private:
157  ServerSocket serverSocket;
158 
160  BlockingServer(const BlockingServer&);
162  BlockingServer& operator=(const BlockingServer&);
163 };
164 
165 
166 } //namespace
167 #endif