21#ifndef G_NET_MULTISERVER_H
22#define G_NET_MULTISERVER_H
38 class MultiServerImp ;
50 G_EXCEPTION( NoListeningAddresses ,
tx(
"no listening addresses") ) ;
51 G_EXCEPTION( InvalidName ,
tx(
"invalid address or interface name") ) ;
52 G_EXCEPTION( InvalidFd ,
tx(
"invalid listening file descriptor number") ) ;
53 using AddressList = std::vector<Address> ;
62 unsigned int port ,
const std::string & server_type ,
80 std::vector<std::weak_ptr<ServerPeer>>
peers() ;
96 void serverReport(
const std::string & group = {} )
const ;
101 void onInterfaceEvent(
const std::string & )
override ;
110 using ServerPtr = std::unique_ptr<MultiServerImp> ;
111 using ServerList = std::vector<ServerPtr> ;
112 bool gotServerFor(
Address )
const ;
113 bool gotAddressFor(
const Listener & ,
const AddressList & )
const ;
114 void onInterfaceEventTimeout() ;
116 static std::string displayString(
const Address & ) ;
118 void createServer(
const Address & ,
bool ) ;
119 void createServer(
const Address & ,
bool , std::nothrow_t ) ;
120 ServerList::iterator removeServer( ServerList::iterator ) ;
125 unsigned int m_port ;
126 std::string m_server_type ;
130 ServerList m_server_list ;
140 MultiServerImp( MultiServer & , ExceptionSink ,
bool fixed ,
const Address & , ServerPeer::Config , Server::Config ) ;
143 MultiServerImp( MultiServer & , ExceptionSink , Descriptor , ServerPeer::Config , Server::Config ) ;
146 ~MultiServerImp()
override ;
149 std::unique_ptr<ServerPeer>
newPeer( ExceptionSinkUnbound , ServerPeerInfo&& ) final ;
155 bool dynamic() const ;
159 MultiServerImp( const MultiServerImp & ) = delete ;
160 MultiServerImp( MultiServerImp && ) = delete ;
161 MultiServerImp & operator=( const MultiServerImp & ) = delete ;
162 MultiServerImp & operator=( MultiServerImp && ) = delete ;
The GNet::Address class encapsulates a TCP/UDP transport address.
A class that encapsulates a network socket file descriptor and an associated windows event handle.
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.
An interface for a network listener.
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
~MultiServer() override
Destructor.
bool hasPeers() const
Returns true if peers() is not empty.
std::vector< std::weak_ptr< ServerPeer > > peers()
Returns the list of ServerPeer-derived objects.
MultiServer(ExceptionSink listener_exception_sink, const G::StringArray &listen_list, unsigned int port, const std::string &server_type, ServerPeer::Config server_peer_config, Server::Config server_config)
Constructor.
void serverReport(const std::string &group={}) const
Writes to the system log a summary of the underlying server objects and their addresses.
std::unique_ptr< ServerPeer > doNewPeer(ExceptionSinkUnbound, ServerPeerInfo &&, const ServerInfo &)
Pseudo-private method used by the pimple class.
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 creates a ServerPeer-derived object.
A move-only structure used in GNet::Server::newPeer() and containing the new socket.
A network server class which listens on a specific port and spins off ServerPeer objects for each inc...
virtual std::unique_ptr< ServerPeer > newPeer(ExceptionSinkUnbound, ServerPeerInfo &&)=0
A factory method which new()s a ServerPeer-derived object.
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.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
A structure used in GNet::MultiServer::newPeer().
Address m_address
The server address that the peer connected to.
A configuration structure for GNet::ServerPeer.
A configuration structure for GNet::Server.