Skip to content

Commit 916c019

Browse files
committed
Update EAP implementation to correctly deal with a socket operation that is completed synchronously.
Fixes #571.
1 parent 8aad18f commit 916c019

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/Renci.SshNet/Abstractions/SocketAbstraction.cs

+20-8
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size
148148
var receiveCompleted = new ManualResetEvent(false);
149149
var sendReceiveToken = new PartialSendReceiveToken(socket, receiveCompleted);
150150
var args = new SocketAsyncEventArgs
151-
{
152-
RemoteEndPoint = socket.RemoteEndPoint,
153-
UserToken = sendReceiveToken
154-
};
151+
{
152+
RemoteEndPoint = socket.RemoteEndPoint,
153+
UserToken = sendReceiveToken
154+
};
155155
args.Completed += ReceiveCompleted;
156156
args.SetBuffer(buffer, offset, size);
157157

@@ -166,6 +166,10 @@ public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size
166166
"Socket read operation has timed out after {0:F0} milliseconds.",
167167
timeout.TotalMilliseconds));
168168
}
169+
else
170+
{
171+
sendReceiveToken.Process(args);
172+
}
169173

170174
if (args.SocketError != SocketError.Success)
171175
throw new SocketException((int) args.SocketError);
@@ -359,10 +363,10 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS
359363
var sendReceiveToken = new BlockingSendReceiveToken(socket, buffer, offset, size, receiveCompleted);
360364

361365
var args = new SocketAsyncEventArgs
362-
{
363-
UserToken = sendReceiveToken,
364-
RemoteEndPoint = socket.RemoteEndPoint
365-
};
366+
{
367+
UserToken = sendReceiveToken,
368+
RemoteEndPoint = socket.RemoteEndPoint
369+
};
366370
args.Completed += ReceiveCompleted;
367371
args.SetBuffer(buffer, offset, size);
368372

@@ -374,6 +378,10 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS
374378
throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture,
375379
"Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds));
376380
}
381+
else
382+
{
383+
sendReceiveToken.Process(args);
384+
}
377385

378386
if (args.SocketError != SocketError.Success)
379387
throw new SocketException((int) args.SocketError);
@@ -443,6 +451,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
443451
if (!sendCompleted.WaitOne())
444452
throw new SocketException((int) SocketError.TimedOut);
445453
}
454+
else
455+
{
456+
sendReceiveToken.Process(socketAsyncSendArgs);
457+
}
446458

447459
if (socketAsyncSendArgs.SocketError != SocketError.Success)
448460
throw new SocketException((int) socketAsyncSendArgs.SocketError);

0 commit comments

Comments
 (0)