mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-17 05:21:15 +08:00
Native async (#1267)
This commit is contained in:
committed by
GitHub
parent
04178d8432
commit
6220beb83d
@@ -325,10 +325,17 @@ namespace Renci.SshNet.Abstractions
|
||||
return totalBytesRead;
|
||||
}
|
||||
|
||||
public static Task<int> ReadAsync(Socket socket, byte[] buffer, int offset, int length, CancellationToken cancellationToken)
|
||||
#if NET6_0_OR_GREATER
|
||||
public static async Task<int> ReadAsync(Socket socket, byte[] buffer, CancellationToken cancellationToken)
|
||||
{
|
||||
return socket.ReceiveAsync(buffer, offset, length, cancellationToken);
|
||||
return await socket.ReceiveAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
#else
|
||||
public static Task<int> ReadAsync(Socket socket, byte[] buffer, CancellationToken cancellationToken)
|
||||
{
|
||||
return socket.ReceiveAsync(buffer, 0, buffer.Length, cancellationToken);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void Send(Socket socket, byte[] data)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -130,3 +131,4 @@ namespace Renci.SshNet.Abstractions
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace Renci.SshNet.Connection
|
||||
// to be processed by subsequent invocations.
|
||||
while (true)
|
||||
{
|
||||
var bytesRead = await SocketAbstraction.ReadAsync(socket, data, 0, data.Length, cancellationToken).ConfigureAwait(false);
|
||||
var bytesRead = await SocketAbstraction.ReadAsync(socket, data, cancellationToken).ConfigureAwait(false);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
throw new SshConnectionException("The connection was closed by the remote host.");
|
||||
|
||||
Reference in New Issue
Block a user