mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-28 14:08:37 +08:00
* Avoid rounding issues when checking Timeout values (#1700) AsTimeout is called from the SshCommand constructor with Timeout.InfiniteTimeSpan. In this scenario the range check should never fail, but unfortunately it does in certain scenarios, due to a runtime or compiler bug (as soon as optimizations are turned off the issue miraculously disappears). Closes #1700 * fix tests --------- Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
This commit is contained in:
co-authored by
Robert Hague
parent
ebdcb3ea7d
commit
c5c6f28d60
@@ -19,9 +19,9 @@ namespace Renci.SshNet.Common
|
||||
/// </exception>
|
||||
public static int AsTimeout(this TimeSpan timeSpan, [CallerArgumentExpression(nameof(timeSpan))] string? paramName = null)
|
||||
{
|
||||
var timeoutInMilliseconds = timeSpan.TotalMilliseconds;
|
||||
return timeoutInMilliseconds is < -1d or > int.MaxValue
|
||||
? throw new ArgumentOutOfRangeException(paramName, "The timeout must represent a value between -1 and Int32.MaxValue milliseconds, inclusive.")
|
||||
var timeoutInMilliseconds = (long)timeSpan.TotalMilliseconds;
|
||||
return timeoutInMilliseconds is < -1 or > int.MaxValue
|
||||
? throw new ArgumentOutOfRangeException(paramName, timeSpan, "The timeout must represent a value between -1 and Int32.MaxValue milliseconds, inclusive.")
|
||||
: (int)timeoutInMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user