admit
virtual bool admit(CServer* server, CMessenger* messenger, cvar& auth);
Return true to accept and take ownership of the messenger. Return false to reject it. Do not delete the messenger during this callback.
Networking
Accept native messenger connections and delegate application admission.
#include <mc/CServer.h>The server borrows a non-null delegate and a running pool. The first message is the authentication value.
Successful admission transfers messenger ownership to the application and sends {"#":"authenticated"}. Rejection closes the pending messenger. Admission callbacks may run concurrently.
The application owns admitted messengers independently of the server. Keep their delegate and pool alive until they close.
class CServerDelegatevirtual bool admit(CServer* server, CMessenger* messenger, cvar& auth);
Return true to accept and take ownership of the messenger. Return false to reject it. Do not delete the messenger during this callback.
class CServerCServer(CServerDelegate* delegate, CPool& pool);
CServer(const CServer&) = delete;
Creates a listener using a non-null borrowed delegate and a borrowed worker pool. Start the pool before accepting connections.
~CServer();
Stops the listener, closes pending authentication connections, and waits for active admission callbacks. Successfully admitted messengers remain owned by the application.
void setDelegate(CServerDelegate* delegate);
Changes the delegate for future admissions without waiting for old callbacks. Keep the old delegate alive until those calls finish.
CServerDelegate* delegate();
Returns the current borrowed admission delegate. It does not retain the delegate or wait for active admissions.
CPool& pool() const;
Returns the borrowed worker pool used for listener and messenger work.
void listen(int port);
Listens on IPv4 INADDR_ANY and replaces the prior listener. A retained asynchronous listener error is rethrown once on the next call.