Protocol¶
Protocol is the base abstraction that TcpListenerBase calls for connection acceptance and per-message processing. It centralizes accepting-state, connection validation, post-processing, auto-disconnect policy, error counting, and a small runtime report surface.
Source mapping¶
src/Nalix.Network/Protocols/Protocol.Core.cssrc/Nalix.Network/Protocols/Protocol.PublicMethods.cssrc/Nalix.Network/Protocols/Protocol.Lifecycle.cssrc/Nalix.Network/Protocols/Protocol.Metrics.cs
Required contract¶
Derived types must implement:
This is the main per-message handler in the connection event pipeline.
Acceptance flow¶
OnAccept(connection, ct) currently:
- rejects immediately if
IsAcceptingis false - validates null, disposed, and cancellation state
- calls
ValidateConnection(connection) - if validation passes, starts
connection.TCP.BeginReceive(ct) - if validation fails, closes the connection
- on unexpected errors, calls
OnConnectionError(...)and disconnects
Post-process flow¶
PostProcessMessage(sender, args):
- calls
OnPostProcess(args) - increments
TotalMessages - disconnects the connection when
KeepConnectionOpenis false - on exceptions, increments
TotalErrors, callsOnConnectionError(...), and disconnects
KeepConnectionOpen is backed by an atomic field and defaults to false.
Extensibility points¶
ValidateConnection(IConnection)for pre-receive admission checksOnPostProcess(IConnectEventArgs)for after-handler logicOnConnectionError(IConnection, Exception)for protocol-level error handlingDispose(bool)for releasing derived resources
Operational controls¶
SetConnectionAcceptance(bool)toggles whether new connections are accepted.IsAcceptingis stored atomically.Dispose()marks the protocol disposed and suppresses finalization.
Basic usage¶
Diagnostics¶
GenerateReport() includes:
- disposed flag
TotalMessagesTotalErrorsIsAcceptingKeepConnectionOpen