66using System . Threading . Tasks ;
77
88using Renci . SshNet . Common ;
9- using Renci . SshNet . Messages . Transport ;
109
1110namespace Renci . SshNet . Abstractions
1211{
@@ -167,11 +166,6 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int
167166 }
168167 catch ( SocketException ex )
169168 {
170- if ( IsErrorResumable ( ex . SocketErrorCode ) )
171- {
172- continue ;
173- }
174-
175169#pragma warning disable IDE0010 // Add missing cases
176170 switch ( ex . SocketErrorCode )
177171 {
@@ -221,7 +215,7 @@ public static int ReadByte(Socket socket, TimeSpan timeout)
221215 public static void SendByte ( Socket socket , byte value )
222216 {
223217 var buffer = new [ ] { value } ;
224- Send ( socket , buffer , 0 , 1 ) ;
218+ _ = socket . Send ( buffer ) ;
225219 }
226220
227221 /// <summary>
@@ -288,22 +282,12 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS
288282
289283 totalBytesRead += bytesRead ;
290284 }
291- catch ( SocketException ex )
285+ catch ( SocketException ex ) when ( ex . SocketErrorCode == SocketError . TimedOut )
292286 {
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 ) ;
307291 }
308292 }
309293 while ( totalBytesRead < totalBytesToRead ) ;
@@ -317,61 +301,6 @@ public static ValueTask<int> ReadAsync(Socket socket, byte[] buffer, Cancellatio
317301 return socket . ReceiveAsync ( new ArraySegment < byte > ( buffer , 0 , buffer . Length ) , SocketFlags . None , cancellationToken ) ;
318302 }
319303#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-
375304 private static void ConnectCompleted ( object sender , SocketAsyncEventArgs e )
376305 {
377306 var eventWaitHandle = ( ManualResetEvent ) e . UserToken ;
0 commit comments