| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Net; |
| | 4 | |
|
| | 5 | | namespace IceRpc.Transports.Tcp; |
| | 6 | |
|
| | 7 | | /// <summary>The base options class for TCP transports.</summary> |
| | 8 | | public record class TcpTransportOptions |
| | 9 | | { |
| | 10 | | /// <summary>Gets or sets a value indicating whether the underlying socket is using the Nagle algorithm. |
| | 11 | | /// </summary> |
| | 12 | | /// <value><see langword="false" /> if the socket uses the Nagle algorithm; otherwise, <see langword="true" />. |
| | 13 | | /// Defaults to <see langword="true" />.</value> |
| | 14 | | public bool NoDelay { get; set; } = true; |
| | 15 | |
|
| | 16 | | /// <summary>Gets or sets the socket receive buffer size in bytes.</summary> |
| | 17 | | /// <value>The receive buffer size in bytes. It can't be less than <c>1</c> KB. <see langword="null" /> means use |
| | 18 | | /// the operating system default. Defaults to <see langword="null" />.</value> |
| | 19 | | public int? ReceiveBufferSize |
| | 20 | | { |
| | 21 | | get => _receiveBufferSize; |
| | 22 | | set => _receiveBufferSize = value is null || value >= 1024 ? value : |
| | 23 | | throw new ArgumentException( |
| | 24 | | $"The {nameof(ReceiveBufferSize)} value cannot be less than 1KB.", |
| | 25 | | nameof(value)); |
| | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary>Gets or sets the socket send buffer size in bytes.</summary> |
| | 29 | | /// <value>The send buffer size in bytes. It can't be less than <c>1</c> KB. <see langword="null" /> means use the |
| | 30 | | /// OS default. Defaults to <see langword="null" />. |
| | 31 | | /// </value> |
| | 32 | | public int? SendBufferSize |
| | 33 | | { |
| | 34 | | get => _sendBufferSize; |
| | 35 | | set => _sendBufferSize = value is null || value >= 1024 ? value : |
| | 36 | | throw new ArgumentException( |
| | 37 | | $"The {nameof(SendBufferSize)} value cannot be less than 1KB.", |
| | 38 | | nameof(value)); |
| | 39 | | } |
| | 40 | |
|
| | 41 | | private int? _receiveBufferSize; |
| | 42 | | private int? _sendBufferSize; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary>The options class for configuring <see cref="TcpClientTransport" />.</summary> |
| | 46 | | public sealed record class TcpClientTransportOptions : TcpTransportOptions |
| | 47 | | { |
| | 48 | | /// <summary>Gets or sets the address and port represented by a .NET <see cref="IPEndPoint"/> to use for a client |
| | 49 | | /// socket. If specified the client socket will bind to this address and port before connection establishment. |
| | 50 | | /// </summary> |
| | 51 | | /// <value>The address and port to bind the socket to. Defaults to <see langword="null" />.</value> |
| 266 | 52 | | public IPEndPoint? LocalNetworkAddress { get; set; } |
| | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary>The options class for configuring <see cref="TcpServerTransport" />.</summary> |
| | 56 | | public sealed record class TcpServerTransportOptions : TcpTransportOptions |
| | 57 | | { |
| | 58 | | /// <summary>Gets or sets the length of the server socket queue for accepting new connections. If a new connection |
| | 59 | | /// request arrives and the queue is full, the client connection establishment will fail with a <see |
| | 60 | | /// cref="IceRpcException" /> and the <see cref="IceRpcError.ConnectionRefused" /> error code.</summary> |
| | 61 | | /// <value>The server socket backlog size. Defaults to <c>511</c>.</value> |
| | 62 | | public int ListenBacklog |
| | 63 | | { |
| | 64 | | get => _listenBacklog; |
| | 65 | | set => _listenBacklog = value > 0 ? value : |
| | 66 | | throw new ArgumentException($"The {nameof(ListenBacklog)} value cannot be less than 1", nameof(value)); |
| | 67 | | } |
| | 68 | |
|
| | 69 | | private int _listenBacklog = 511; |
| | 70 | | } |