Refactoring connection to use an idle timeout and automatically close the underlying data channel

This commit is contained in:
2024-03-31 22:29:07 +02:00
parent 967d80ff3f
commit a58af4d75f
16 changed files with 812 additions and 1198 deletions

View File

@@ -16,23 +16,14 @@ namespace AMWD.Protocols.Modbus.Common.Contracts
string Name { get; }
/// <summary>
/// Gets a value indicating whether the connection is open.
/// Gets or sets the idle time after that the connection is closed.
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Opens the connection to the remote device.
/// </summary>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
/// <returns>An awaitable <see cref="Task"/>.</returns>
Task ConnectAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Closes the connection to the remote device.
/// </summary>
/// <param name="cancellationToken">A cancellation token used to propagate notification that this operation should be canceled.</param>
/// <returns>An awaitable <see cref="Task"/>.</returns>
Task DisconnectAsync(CancellationToken cancellationToken = default);
/// <remarks>
/// Set to <see cref="Timeout.InfiniteTimeSpan"/> to disable idle closing the connection.
/// <br/>
/// Set to <see cref="TimeSpan.Zero"/> to close the connection immediately after each request.
/// </remarks>
TimeSpan IdleTimeout { get; set; }
/// <summary>
/// Invokes a Modbus request.