6
6
using System . Threading . Tasks ;
7
7
8
8
using Renci . SshNet . Common ;
9
- using Renci . SshNet . Messages . Transport ;
10
9
11
10
namespace Renci . SshNet . Abstractions
12
11
{
@@ -167,11 +166,6 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int
167
166
}
168
167
catch ( SocketException ex )
169
168
{
170
- if ( IsErrorResumable ( ex . SocketErrorCode ) )
171
- {
172
- continue ;
173
- }
174
-
175
169
#pragma warning disable IDE0010 // Add missing cases
176
170
switch ( ex . SocketErrorCode )
177
171
{
@@ -221,7 +215,7 @@ public static int ReadByte(Socket socket, TimeSpan timeout)
221
215
public static void SendByte ( Socket socket , byte value )
222
216
{
223
217
var buffer = new [ ] { value } ;
224
- Send ( socket , buffer , 0 , 1 ) ;
218
+ _ = socket . Send ( buffer ) ;
225
219
}
226
220
227
221
/// <summary>
@@ -288,22 +282,12 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS
288
282
289
283
totalBytesRead += bytesRead ;
290
284
}
291
- catch ( SocketException ex )
285
+ catch ( SocketException ex ) when ( ex . SocketErrorCode == SocketError . TimedOut )
292
286
{
293
- if ( IsErrorResumable ( ex . SocketErrorCode ) )
294
- {
295
- ThreadAbstraction . Sleep ( 30 ) ;
296
- continue ;
297
- }
298
-
299
- if ( ex . SocketErrorCode == SocketError . TimedOut )
300
- {
301
- throw new SshOperationTimeoutException ( string . Format ( CultureInfo . InvariantCulture ,
302
- "Socket read operation has timed out after {0:F0} milliseconds." ,
303
- readTimeout . TotalMilliseconds ) ) ;
304
- }
305
-
306
- throw ;
287
+ throw new SshOperationTimeoutException ( string . Format ( CultureInfo . InvariantCulture ,
288
+ "Socket read operation has timed out after {0:F0} milliseconds." ,
289
+ readTimeout . TotalMilliseconds ) ,
290
+ ex ) ;
307
291
}
308
292
}
309
293
while ( totalBytesRead < totalBytesToRead ) ;
@@ -317,61 +301,6 @@ public static ValueTask<int> ReadAsync(Socket socket, byte[] buffer, Cancellatio
317
301
return socket . ReceiveAsync ( new ArraySegment < byte > ( buffer , 0 , buffer . Length ) , SocketFlags . None , cancellationToken ) ;
318
302
}
319
303
#endif
320
-
321
- public static void Send ( Socket socket , byte [ ] data )
322
- {
323
- Send ( socket , data , 0 , data . Length ) ;
324
- }
325
-
326
- public static void Send ( Socket socket , byte [ ] data , int offset , int size )
327
- {
328
- var totalBytesSent = 0 ; // how many bytes are already sent
329
- var totalBytesToSend = size ;
330
-
331
- do
332
- {
333
- try
334
- {
335
- var bytesSent = socket . Send ( data , offset + totalBytesSent , totalBytesToSend - totalBytesSent , SocketFlags . None ) ;
336
- if ( bytesSent == 0 )
337
- {
338
- throw new SshConnectionException ( "An established connection was aborted by the server." ,
339
- DisconnectReason . ConnectionLost ) ;
340
- }
341
-
342
- totalBytesSent += bytesSent ;
343
- }
344
- catch ( SocketException ex )
345
- {
346
- if ( IsErrorResumable ( ex . SocketErrorCode ) )
347
- {
348
- // socket buffer is probably full, wait and try again
349
- ThreadAbstraction . Sleep ( 30 ) ;
350
- }
351
- else
352
- {
353
- throw ; // any serious error occurr
354
- }
355
- }
356
- }
357
- while ( totalBytesSent < totalBytesToSend ) ;
358
- }
359
-
360
- public static bool IsErrorResumable ( SocketError socketError )
361
- {
362
- #pragma warning disable IDE0010 // Add missing cases
363
- switch ( socketError )
364
- {
365
- case SocketError . WouldBlock :
366
- case SocketError . IOPending :
367
- case SocketError . NoBufferSpaceAvailable :
368
- return true ;
369
- default :
370
- return false ;
371
- }
372
- #pragma warning restore IDE0010 // Add missing cases
373
- }
374
-
375
304
private static void ConnectCompleted ( object sender , SocketAsyncEventArgs e )
376
305
{
377
306
var eventWaitHandle = ( ManualResetEvent ) e . UserToken ;
0 commit comments