Wojciech Nagórski преди 1 година
родител
ревизия
6220beb83d

+ 9 - 2
src/Renci.SshNet/Abstractions/SocketAbstraction.cs

@@ -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)
         {

+ 3 - 1
src/Renci.SshNet/Abstractions/SocketExtensions.cs

@@ -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

+ 1 - 1
src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

@@ -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.");