Path: redb-route/redb.Route.Tcp/TcpEndpointOptions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Tcp/TcpEndpointOptions.cs ---- using redb.Route.Core; namespace redb.Route.Tcp; /// /// Options for the TCP endpoint. Shared by both producer and consumer. /// Use URI parameters to configure: tcp:host:port?textLine=true&delimiter=\n /// public class TcpEndpointOptions : EndpointOptions { // ── Connection ────────────────────────────────────── /// Remote host (producer) or bind host (consumer). Parsed from URI path. public string Host { get; set; } = "0.0.0.0"; /// Remote port (producer) or bind port (consumer). Parsed from URI path. public int Port { get; set; } // ── Framing ───────────────────────────────────────── /// Message framing mode. Default: Raw. public TcpFraming Framing { get; set; } = TcpFraming.Raw; /// /// Shortcut: set to true to use TextLine framing. /// Equivalent to Framing=TextLine. Default: false. /// public bool TextLine { get; set; } /// /// Shortcut: set to true to use LengthPrefixed framing. /// Equivalent to Framing=LengthPrefixed. Default: false. /// public bool LengthPrefixed { get; set; } /// /// Delimiter for TextLine framing. Default: "\n". /// Supports common escape sequences: \n, \r\n, \r. /// public string Delimiter { get; set; } = "\n"; /// Text encoding name for TextLine framing and string body conversion. Default: utf-8. public string Encoding { get; set; } = "utf-8"; // ── Socket options ────────────────────────────────── /// TCP keep-alive. Default: true. public bool KeepAlive { get; set; } = true; /// Disable Nagle's algorithm for low-latency. Default: true. public bool NoDelay { get; set; } = true; /// /// Socket receive buffer (SO_RCVBUF) in bytes. Default 0: the system sizes the buffer and grows it with the /// traffic. A fixed size switches that tuning off on Linux; 8192 there, on loopback, let a 64 KiB frame through /// in about three seconds, because the window stayed below one segment. The Raw and TextLine reads use the same /// value as their chunk size, or when it is 0. /// public int ReceiveBufferSize { get; set; } /// Socket send buffer (SO_SNDBUF) in bytes. Default 0: the system sizes the buffer. public int SendBufferSize { get; set; } /// The chunk size of a Raw or TextLine read when is 0. public const int DefaultReadChunkSize = 8192; /// The chunk size the Raw and TextLine reads use. internal int ReadChunkSize => ReceiveBufferSize > 0 ? ReceiveBufferSize : DefaultReadChunkSize; /// Applies the buffer sizes that were set; a 0 leaves the system's own size in place. internal void ApplyBufferSizes(System.Net.Sockets.TcpClient client) { if (ReceiveBufferSize > 0) client.ReceiveBufferSize = ReceiveBufferSize; if (SendBufferSize > 0) client.SendBufferSize = SendBufferSize; } // ── Producer (client) ─────────────────────────────── /// Connect timeout in milliseconds. Default: 10000 (10s). 0 = infinite. public int ConnectTimeout { get; set; } = 10_000; /// Auto-reconnect on disconnect. Default: false. public bool Reconnect { get; set; } /// Interval between reconnect attempts in milliseconds. Default: 5000. public int ReconnectInterval { get; set; } = 5_000; /// Maximum reconnect attempts. 0 = unlimited. Default: 0. public int MaxReconnectAttempts { get; set; } // ── Consumer (server) ─────────────────────────────── /// Listen backlog for the TCP server. Default: 128. public int Backlog { get; set; } = 128; /// Maximum concurrent client connections. 0 = unlimited. Default: 0. public int MaxConnections { get; set; } /// /// If true, the consumer returns the exchange Out body as the TCP response (InOut pattern). /// If false, processes the message without responding (InOnly). Default: false. /// public bool InOut { get; set; } // ── TLS ───────────────────────────────────────────── /// Enable TLS encryption. Default: false. public bool Ssl { get; set; } /// Path to PFX certificate file for TLS (consumer). Required when ssl=true for consumer. public string? SslCertPath { get; set; } /// Password for the PFX certificate. [Sensitive] public string? SslCertPassword { get; set; } /// /// Named from the route registry. Lets the TLS certificate /// password live in the registry instead of the endpoint URI, so it never reaches logs /// or dashboards. /// [RegistryReference(typeof(TcpConnectionFactory))] public string? ConnectionFactory { get; set; } /// /// Target host name for TLS server certificate validation (producer). /// If not set, uses the Host value. /// public string? SslTargetHost { get; set; } /// /// Producer only: accept any server certificate, including a self-signed one. Off by default /// and never implied by another option — a staging server behind a self-signed certificate is /// a real need, but switching validation off has to be a decision someone wrote down. /// public bool TrustAllCertificates { get; set; } /// /// Producer only: PFX client certificate presented to a server that requires mTLS. Distinct /// from , which is the certificate a consumer serves; naming follows /// the gRPC connector's clientCertPath. /// public string? ClientCertPath { get; set; } /// Password for . [Sensitive] public string? ClientCertPassword { get; set; } /// public override void Validate() { if (Port is < 0 or > 65535) throw new ArgumentException("Port must be between 0 and 65535."); if (ReceiveBufferSize < 0) throw new ArgumentException("ReceiveBufferSize must be >= 0 (0: the system's own size)."); if (SendBufferSize < 0) throw new ArgumentException("SendBufferSize must be >= 0 (0: the system's own size)."); if (ConnectTimeout < 0) throw new ArgumentException("ConnectTimeout must be >= 0."); if (ReconnectInterval <= 0) throw new ArgumentException("ReconnectInterval must be > 0."); if (MaxReconnectAttempts < 0) throw new ArgumentException("MaxReconnectAttempts must be >= 0."); if (Backlog <= 0) throw new ArgumentException("Backlog must be > 0."); if (MaxConnections < 0) throw new ArgumentException("MaxConnections must be >= 0."); // Resolve framing shortcuts if (TextLine) Framing = TcpFraming.TextLine; if (LengthPrefixed) Framing = TcpFraming.LengthPrefixed; if (TextLine && LengthPrefixed) throw new ArgumentException("Cannot enable both TextLine and LengthPrefixed framing."); } }