Networking

CServer

Accept native messenger connections and delegate application admission.

C++23 mc/CServer.h
#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.

Jump to a declaration · 10

CServerDelegate

Methods

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.

CServer

class CServer

Methods

~CServer

~CServer();

Stops the listener, closes pending authentication connections, and waits for active admission callbacks. Successfully admitted messengers remain owned by the application.

setDelegate

void setDelegate(CServerDelegate* delegate);

Changes the delegate for future admissions without waiting for old callbacks. Keep the old delegate alive until those calls finish.

delegate

CServerDelegate* delegate();

Returns the current borrowed admission delegate. It does not retain the delegate or wait for active admissions.

pool

CPool& pool() const;

Returns the borrowed worker pool used for listener and messenger work.

listen

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.