-
-
Notifications
You must be signed in to change notification settings - Fork 952
Plumbing for more async/await work #1281
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 9 commits into
sshnet:develop
from
jacobslusser:jacob/async_merge
Jan 25, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
93647d9
Changes _socketDisposeLock to a SemaphoreSlim so it can play nice wit…
jacobslusser 2ef5d3f
Adds a SendAsync method for .NET6+
jacobslusser 2d53224
Merge branch 'develop' into jacob/async_merge
jacobslusser 3018916
Merge remote-tracking branch 'upstream/develop' into jacob/async_merge
Rob-Hague a771894
Merge branch 'develop' into jacob/async_merge
WojciechNagorski 2699443
Merge remote-tracking branch 'upstream/develop' into jacob/async_merge
Rob-Hague f538899
Fix false positive analyzer error
Rob-Hague d89a56c
Formatting
jacobslusser 49630ad
Merge branch 'jacob/async_merge' of https://github.com/jacobslusser/S…
jacobslusser 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Renci.SshNet.Abstractions | ||
{ | ||
internal static partial class SocketAbstraction | ||
{ | ||
public static ValueTask<int> ReadAsync(Socket socket, byte[] buffer, CancellationToken cancellationToken) | ||
{ | ||
return socket.ReceiveAsync(buffer, SocketFlags.None, cancellationToken); | ||
} | ||
|
||
public static ValueTask SendAsync(Socket socket, ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default) | ||
{ | ||
Debug.Assert(socket != null); | ||
Debug.Assert(data.Length > 0); | ||
|
||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
return ValueTask.FromCanceled(cancellationToken); | ||
} | ||
|
||
return SendAsyncCore(socket, data, cancellationToken); | ||
|
||
static async ValueTask SendAsyncCore(Socket socket, ReadOnlyMemory<byte> data, CancellationToken cancellationToken) | ||
{ | ||
do | ||
{ | ||
try | ||
{ | ||
var bytesSent = await socket.SendAsync(data, SocketFlags.None, cancellationToken).ConfigureAwait(false); | ||
data = data.Slice(bytesSent); | ||
} | ||
catch (SocketException ex) when (IsErrorResumable(ex.SocketErrorCode)) | ||
{ | ||
// Buffer may be full; attempt a short delay and retry | ||
await Task.Delay(30, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
while (data.Length > 0); | ||
} | ||
} | ||
} | ||
} | ||
#endif // NET6_0_OR_GREATER |
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.