21#ifndef G_NET_MULTISERVER_H
22#define G_NET_MULTISERVER_H
35 class MultiServerImp ;
47 using AddressList = std::vector<Address> ;
48 G_EXCEPTION( NoListeningAddresses ,
"no listening addresses" ) ;
49 G_EXCEPTION( InvalidName ,
"invalid address or interface name" ) ;
58 unsigned int port ,
const std::string & server_type ,
ServerPeerConfig server_peer_config ,
73 std::vector<std::weak_ptr<ServerPeer> >
peers() ;
76 static bool canBind(
const AddressList & listening_address_list ,
bool do_throw ) ;
99 void onInterfaceEvent(
const std::string & )
override ;
109 AddressList addresses(
unsigned int )
const ;
111 void init(
const AddressList & address_list ) ;
112 bool gotServerFor(
const Address & )
const ;
113 void onInterfaceEventTimeout() ;
115 static std::string displayString(
const Address & ) ;
118 using ServerPtr = std::unique_ptr<MultiServerImp> ;
119 using ServerList = std::vector<ServerPtr> ;
122 unsigned int m_port ;
123 std::string m_server_type ;
127 ServerList m_server_list ;
The GNet::Address class encapsulates a TCP/UDP transport address.
A potential ExceptionSink that is realised by bind()ing an exception source pointer.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
An interface for receiving notification of network changes.
A class for getting a list of network interfaces and their addresses.
A GNet::Server class used in GNet::MultiServer.
std::unique_ptr< ServerPeer > newPeer(ExceptionSinkUnbound, ServerPeerInfo) final
Called by the base class to create a new ServerPeer.
~MultiServerImp() override
Destructor.
MultiServerImp(MultiServer &, ExceptionSink, const Address &, ServerPeerConfig, ServerConfig)
Constructor.
void cleanup()
Calls GNet::Server::serverCleanup().
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
~MultiServer() override
Destructor.
static bool canBind(const AddressList &listening_address_list, bool do_throw)
Checks that all the specified addresses can be bound.
bool hasPeers() const
Returns true if peers() is not empty.
std::vector< std::weak_ptr< ServerPeer > > peers()
Returns the list of ServerPeer-derived objects.
void serverReport() const
Writes to the system log a summary of the underlying server objects and their addresses.
MultiServer(ExceptionSink listener_exception_sink, const G::StringArray &addresses, unsigned int port, const std::string &server_type, ServerPeerConfig server_peer_config, ServerConfig server_config)
Constructor.
void serverCleanup()
Should be called from all derived classes' destructors so that peer objects can use their Server obje...
virtual std::unique_ptr< ServerPeer > newPeer(ExceptionSinkUnbound, ServerPeerInfo, ServerInfo)=0
A factory method which new()s a ServerPeer-derived object.
std::unique_ptr< ServerPeer > doNewPeer(ExceptionSinkUnbound, const ServerPeerInfo &, const ServerInfo &)
Pseudo-private method used by the pimple class.
A structure that GNet::Server uses to configure its ServerPeer objects.
A structure used in GNet::Server::newPeer().
A network server class which listens on a specific port and spins off ServerPeer objects for each inc...
A timer class template in which the timeout is delivered to the specified method.
std::vector< std::string > StringArray
A std::vector of std::strings.
A structure used in GNet::MultiServer::newPeer().
Address m_address
The server address that the peer connected to.
A configuration structure for GNet::Server.