- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
43 class GNet::MultiServerImp : public GNet::Server
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
68 class GNet::MultiServerPtr
69 {
70 public:
71 typedef GNet::MultiServerImp ServerImp ;
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
102 class GNet::MultiServer
103 {
104 public:
105 typedef std::list<Address> AddressList ;
106 typedef Server::PeerInfo PeerInfo ;
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
GNet::MultiServerPtr::MultiServerPtr
MultiServerPtr(ServerImp *=NULL)
Constructor.
Definition: gmultiserver.cpp:180
GNet::MultiServer::addressList
static AddressList addressList(const Address &)
A trivial convenience fuction that returns the given addresses as a single-element list...
Definition: gmultiserver.cpp:41
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
gserver.h
GNet::MultiServerPtr
A private implementation class used by GNet::MultiServer.
Definition: gmultiserver.h:68
GNet::MultiServer::MultiServer
MultiServer()
Default constructor. Initialise with init().
Definition: gmultiserver.cpp:95
GNet
Network classes.
GNet::MultiServerPtr::swap
void swap(MultiServerPtr &)
Swaps internals with the other.
Definition: gmultiserver.cpp:200
G::Strings
std::list< std::string > Strings
A std::list of std::strings.
Definition: gstrings.h:39
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
GNet::MultiServer::PeerInfo
Server::PeerInfo PeerInfo
Definition: gmultiserver.h:106
GNet::ConnectionLookup
A class for getting more information about a connection from the operating system.
Definition: gconnectionlookup.h:42
GNet::Server
A network server class which listens on a specific port and spins off ServerPeer objects for each inc...
Definition: gserver.h:83
GNet::MultiServerImp::newPeer
virtual ServerPeer * newPeer(PeerInfo)
Server peer factory method.
Definition: gmultiserver.cpp:168
GNet::MultiServer::canBind
static bool canBind(const AddressList &listening_address_list, bool do_throw)
Checks that the specified addresses can be bound.
Definition: gmultiserver.cpp:31
GNet::MultiServerPtr::ServerImp
GNet::MultiServerImp ServerImp
Definition: gmultiserver.h:71
GNet::MultiServerImp::cleanup
void cleanup()
Does cleanup.
Definition: gmultiserver.cpp:173
GNet::MultiServer::newPeer
virtual ServerPeer * newPeer(PeerInfo)=0
A factory method which new()s a ServerPeer-derived object.
gconnectionlookup.h
GNet::MultiServer::~MultiServer
virtual ~MultiServer()
Destructor.
Definition: gmultiserver.cpp:116
GNet::MultiServerImp
A private implementation class used by GNet::MultiServer.
Definition: gmultiserver.h:43
GNet::MultiServer::init
void init(const AddressList &address_list)
Initilisation after default construction.
Definition: gmultiserver.cpp:99
GNet::MultiServerImp::MultiServerImp
MultiServerImp(MultiServer &ms, const Address &, ConnectionLookup *)
Constructor.
Definition: gmultiserver.cpp:161
GNet::MultiServer::AddressList
std::list< Address > AddressList
Definition: gmultiserver.h:105
GNet::MultiServer::serverCleanup
void serverCleanup()
Should be called from all derived classes' destructors so that peer objects can use their Server obje...
Definition: gmultiserver.cpp:121
GNet::MultiServerPtr::~MultiServerPtr
~MultiServerPtr()
Destructor.
Definition: gmultiserver.cpp:190
GNet::MultiServer
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
GNet::MultiServer::firstAddress
std::pair< bool, Address > firstAddress() const
Returns the first listening address.
Definition: gmultiserver.cpp:144
GNet::Server::PeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91
GNet::MultiServer::serverReport
void serverReport(const std::string &server_type) const
Writes to the system log a summary of the underlying server objects and their addresses.
Definition: gmultiserver.cpp:135
GNet::MultiServerPtr::operator=
void operator=(const MultiServerPtr &)
Assignment operator.
Definition: gmultiserver.cpp:195