Fixed wrong R/W timeout handling on tcp listener handling. v0.4.2
This commit is contained in:
@@ -213,23 +213,32 @@ namespace AMWD.Protocols.Modbus.Tcp
|
||||
{
|
||||
var requestBytes = new List<byte>();
|
||||
|
||||
// Waiting for next request
|
||||
byte[] headerBytes = await stream.ReadExpectedBytesAsync(6, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
||||
requestBytes.AddRange(headerBytes);
|
||||
|
||||
ushort length = headerBytes
|
||||
.Skip(4).Take(2).ToArray()
|
||||
.GetBigEndianUInt16();
|
||||
|
||||
// Waiting for the remaining required data
|
||||
using (var cts = new CancellationTokenSource(ReadWriteTimeout))
|
||||
using (cancellationToken.Register(cts.Cancel))
|
||||
{
|
||||
byte[] headerBytes = await stream.ReadExpectedBytesAsync(6, cts.Token).ConfigureAwait(continueOnCapturedContext: false);
|
||||
requestBytes.AddRange(headerBytes);
|
||||
|
||||
ushort length = headerBytes
|
||||
.Skip(4).Take(2).ToArray()
|
||||
.GetBigEndianUInt16();
|
||||
|
||||
byte[] bodyBytes = await stream.ReadExpectedBytesAsync(length, cts.Token).ConfigureAwait(continueOnCapturedContext: false);
|
||||
requestBytes.AddRange(bodyBytes);
|
||||
}
|
||||
|
||||
byte[] responseBytes = await HandleRequestAsync([.. requestBytes], cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
||||
if (responseBytes != null)
|
||||
await stream.WriteAsync(responseBytes, 0, responseBytes.Length, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
|
||||
{
|
||||
// Write response when available
|
||||
using (var cts = new CancellationTokenSource(ReadWriteTimeout))
|
||||
using (cancellationToken.Register(cts.Cancel))
|
||||
{
|
||||
await stream.WriteAsync(responseBytes, 0, responseBytes.Length, cts.Token).ConfigureAwait(continueOnCapturedContext: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
_nothing changed yet_
|
||||
|
||||
|
||||
## [v0.4.2] (2025-02-07)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixing issue with R/W timeouts while processing client requests on the `ModbusTcpProxy`.
|
||||
|
||||
|
||||
## [v0.4.1] (2025-02-06)
|
||||
|
||||
### Changed
|
||||
@@ -87,7 +95,8 @@ So this tag is only here for documentation purposes of the NuGet Gallery.
|
||||
|
||||
|
||||
|
||||
[Unreleased]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.4.1...HEAD
|
||||
[Unreleased]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.4.2...HEAD
|
||||
[v0.4.2]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.4.1...v0.4.2
|
||||
[v0.4.1]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.4.0...v0.4.1
|
||||
[v0.4.0]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.3.2...v0.4.0
|
||||
[v0.3.2]: https://github.com/AM-WD/AMWD.Protocols.Modbus/compare/v0.3.1...v0.3.2
|
||||
|
||||
Reference in New Issue
Block a user