gmultiserver.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program 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 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20 
21 #ifndef G_MULTI_SERVER_H
22 #define G_MULTI_SERVER_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gserver.h"
27 #include "gconnectionlookup.h"
28 #include <list>
29 #include <utility> // std::pair<>
30 
32 namespace GNet
33 {
34  class MultiServer ;
35  class MultiServerImp ;
36  class MultiServerPtr ;
37 }
38 
44 {
45 public:
46  MultiServerImp( MultiServer & ms , const Address & , ConnectionLookup * ) ;
48 
49  void cleanup() ;
51 
52 protected:
53  virtual ServerPeer * newPeer( PeerInfo ) ;
56 
57 private:
58  MultiServer & m_ms ;
59 } ;
60 
69 {
70 public:
72 
73  explicit MultiServerPtr( ServerImp * = NULL ) ;
75 
76  ~MultiServerPtr() ;
78 
79  void swap( MultiServerPtr & ) ;
81 
82  MultiServerImp * get() ;
84 
85  const MultiServerImp * get() const ;
87 
88  MultiServerPtr( const MultiServerPtr & ) ;
90 
91  void operator=( const MultiServerPtr & ) ;
93 
94 private:
95  MultiServerImp * m_p ;
96 } ;
97 
103 {
104 public:
105  typedef std::list<Address> AddressList ;
107 
108  static bool canBind( const AddressList & listening_address_list , bool do_throw ) ;
112 
113  static AddressList addressList( const Address & ) ;
116 
117  static AddressList addressList( const AddressList & , unsigned int port ) ;
121 
122  static AddressList addressList( const G::Strings & , unsigned int port ) ;
128 
129  MultiServer( const AddressList & address_list , bool use_connection_lookup ) ;
138 
139  MultiServer() ;
141 
142  void init( const AddressList & address_list ) ;
146 
147  virtual ~MultiServer() ;
149 
150  std::pair<bool,Address> firstAddress() const ;
153 
154  virtual ServerPeer * newPeer( PeerInfo ) = 0 ;
157 
158 protected:
159  void serverCleanup() ;
163 
164  void serverReport( const std::string & server_type ) const ;
167 
168 private:
169  MultiServer( const MultiServer & ) ; // not implemented
170  void operator=( const MultiServer & ) ; // not implemented
171  void init( const Address & , ConnectionLookup * ) ;
172 
173 private:
174  typedef std::list<MultiServerPtr> List ;
175  std::auto_ptr<GNet::ConnectionLookup> m_connection_lookup ;
176  List m_server_list ;
177 } ;
178 
179 #endif
MultiServerPtr(ServerImp *=NULL)
Constructor.
static AddressList addressList(const Address &)
A trivial convenience fuction that returns the given addresses as a single-element list...
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
A private implementation class used by GNet::MultiServer.
Definition: gmultiserver.h:68
MultiServer()
Default constructor. Initialise with init().
Network classes.
void swap(MultiServerPtr &)
Swaps internals with the other.
std::list< std::string > Strings
A std::list of std::strings.
Definition: gstrings.h:39
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
Server::PeerInfo PeerInfo
Definition: gmultiserver.h:106
A class for getting more information about a connection from the operating system.
A network server class which listens on a specific port and spins off ServerPeer objects for each inc...
Definition: gserver.h:83
virtual ServerPeer * newPeer(PeerInfo)
Server peer factory method.
static bool canBind(const AddressList &listening_address_list, bool do_throw)
Checks that the specified addresses can be bound.
GNet::MultiServerImp ServerImp
Definition: gmultiserver.h:71
void cleanup()
Does cleanup.
virtual ServerPeer * newPeer(PeerInfo)=0
A factory method which new()s a ServerPeer-derived object.
virtual ~MultiServer()
Destructor.
A private implementation class used by GNet::MultiServer.
Definition: gmultiserver.h:43
void init(const AddressList &address_list)
Initilisation after default construction.
MultiServerImp(MultiServer &ms, const Address &, ConnectionLookup *)
Constructor.
std::list< Address > AddressList
Definition: gmultiserver.h:105
void serverCleanup()
Should be called from all derived classes' destructors so that peer objects can use their Server obje...
~MultiServerPtr()
Destructor.
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
std::pair< bool, Address > firstAddress() const
Returns the first listening address.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91
void serverReport(const std::string &server_type) const
Writes to the system log a summary of the underlying server objects and their addresses.
void operator=(const MultiServerPtr &)
Assignment operator.