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 using AddressList = std::vector<Address> ;
61 unsigned int port ,
const std::string & server_type ,
79 std::vector<std::weak_ptr<ServerPeer>>
peers() ;
97 void serverReport(
const std::string & group = {} )
const ;
102 void onInterfaceEvent(
const std::string & )
override ;
111 using ServerPtr = std::unique_ptr<MultiServerImp> ;
112 using ServerList = std::vector<ServerPtr> ;
113 bool gotServerFor(
Address )
const ;
114 bool gotAddressFor(
const Listener & ,
const AddressList & )
const ;
115 void onInterfaceEventTimeout() ;
117 static std::string displayString(
const Address & ) ;
119 void createServer(
const Address & ,
bool ) ;
120 void createServer(
const Address & ,
bool , std::nothrow_t ) ;
121 ServerList::iterator removeServer( ServerList::iterator ) ;
126 unsigned int m_port ;
127 std::string m_server_type ;
131 ServerList m_server_list ;
141 MultiServerImp( MultiServer & , EventState ,
bool fixed ,
const Address & , ServerPeer::Config , Server::Config ) ;
144 MultiServerImp( MultiServer & , EventState , Descriptor , ServerPeer::Config , Server::Config ) ;
147 ~MultiServerImp()
override ;
150 std::unique_ptr<ServerPeer>
newPeer( EventStateUnbound , ServerPeerInfo&& ) final ;
156 bool dynamic() const ;
160 MultiServerImp( const MultiServerImp & ) = delete ;
161 MultiServerImp( MultiServerImp && ) = delete ;
162 MultiServerImp & operator=( const MultiServerImp & ) = delete ;
163 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.
The EventStateUnbound class is used as a device to force factory methods to plumb-in an ExceptionSour...
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
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.
virtual std::unique_ptr< ServerPeer > newPeer(EventStateUnbound, ServerPeerInfo &&, ServerInfo)=0
A factory method which creates a ServerPeer-derived object.
std::unique_ptr< ServerPeer > doNewPeer(EventStateUnbound, ServerPeerInfo &&, const ServerInfo &)
Pseudo-private method used by the pimple class.
void serverReport(const std::string &group={}) const
Writes to the system log a summary of the underlying server objects and their addresses.
MultiServer(EventState es_listener, const G::StringArray &listen_list, unsigned int port, const std::string &server_type, ServerPeer::Config server_peer_config, Server::Config server_config)
Constructor.
void serverCleanup()
Should be called from all derived classes' destructors so that peer objects can use their Server obje...
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(EventStateUnbound, 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) noexcept
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.