-
-
Notifications
You must be signed in to change notification settings - Fork 970
Limit TimeSpan timeouts to Int32 MaxValue #1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WojciechNagorski
merged 13 commits into
sshnet:develop
from
jscarle:feature/ConnectionInfoTimeout
Feb 20, 2024
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ad2451
Added guard clauses to various timeouts to ensure they don't exceed a…
jscarle 76f2878
Merge branch 'develop' into feature/ConnectionInfoTimeout
jscarle 1ba6a63
Merge branch 'develop' into feature/ConnectionInfoTimeout
jscarle 132e3ec
Fixed guard clauses.
jscarle e7afbd4
Updated build tags.
jscarle 5b1a111
Added guard clauses to various timeouts to ensure they don't exceed a…
jscarle 1564121
Merge branch 'feature/ConnectionInfoTimeout_v2' into feature/Connecti…
jscarle 7bdd6f1
Fixed tests.
jscarle c3273b0
Added additional tests.
jscarle b4127ac
Replaced NoWarn with .editorconfig setting
jscarle 25feb4c
Merge branch 'develop' into feature/ConnectionInfoTimeout
jscarle e13d3f5
Merge branch 'develop' into feature/ConnectionInfoTimeout
jscarle f229e42
Fixed references to parameter names.
jscarle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| #if NET21_OR_GREATER || NET6_0_OR_GREATER | ||
| using System.Runtime.CompilerServices; | ||
| #endif | ||
|
|
||
| namespace Renci.SshNet.Common | ||
| { | ||
| /// <summary> | ||
| /// Provides extension methods for <see cref="TimeSpan"/>. | ||
| /// </summary> | ||
| internal static class TimeSpanExtensions | ||
| { | ||
| /// <summary> | ||
| /// Returns the specified <paramref name="timeSpan"/> as a valid timeout in milliseconds. | ||
| /// </summary> | ||
| /// <param name="timeSpan">The <see cref="TimeSpan"/> to ensure validity.</param> | ||
| /// <param name="callerMemberName">The name of the calling member.</param> | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// Thrown when <paramref name="timeSpan"/> does not represent a value between -1 and <see cref="int.MaxValue"/>, inclusive. | ||
| /// </exception> | ||
| public static int AsTimeout(this TimeSpan timeSpan, | ||
| #if NET21_OR_GREATER || NET6_0_OR_GREATER | ||
| [CallerArgumentExpression(nameof(timeSpan))] | ||
| #endif | ||
| string callerMemberName = "") | ||
| { | ||
| var timeoutInMilliseconds = timeSpan.TotalMilliseconds; | ||
| return timeoutInMilliseconds is < -1d or > int.MaxValue | ||
jscarle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ? throw new ArgumentOutOfRangeException(callerMemberName, "The timeout must represent a value between -1 and Int32.MaxValue, inclusive.") | ||
jscarle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| : (int) timeoutInMilliseconds; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Ensures that the specified <paramref name="timeSpan"/> represents a valid timeout in milliseconds. | ||
| /// </summary> | ||
| /// <param name="timeSpan">The <see cref="TimeSpan"/> to ensure validity.</param> | ||
| /// <param name="callerMemberName">The name of the calling member.</param> | ||
| /// <exception cref="ArgumentOutOfRangeException"> | ||
| /// Thrown when <paramref name="timeSpan"/> does not represent a value between -1 and <see cref="int.MaxValue"/>, inclusive. | ||
| /// </exception> | ||
| public static void EnsureValidTimeout(this TimeSpan timeSpan, | ||
| #if NET21_OR_GREATER || NET6_0_OR_GREATER | ||
| [CallerArgumentExpression(nameof(timeSpan))] | ||
| #endif | ||
| string callerMemberName = "") | ||
| { | ||
| var timeoutInMilliseconds = timeSpan.TotalMilliseconds; | ||
| if (timeoutInMilliseconds is < -1d or > int.MaxValue) | ||
| { | ||
| throw new ArgumentOutOfRangeException(callerMemberName, "The timeout must represent a value between -1 and Int32.MaxValue, inclusive."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.