@@ -368,6 +368,20 @@ private void CleanSend()
368
368
_sendContext . Promise = null ;
369
369
}
370
370
371
+ private void CompleteSend ( )
372
+ {
373
+ var promise = _sendContext . Promise ;
374
+ CleanSend ( ) ;
375
+ promise . SetResult ( SuccessResult ) ;
376
+ }
377
+
378
+ private void FaultSend ( Exception ex )
379
+ {
380
+ var promise = _sendContext . Promise ;
381
+ CleanSend ( ) ;
382
+ promise . SetException ( ex ) ;
383
+ }
384
+
371
385
// Async send loop body
372
386
private static void OnSendCompleted ( ISocket sender , ISocketAsyncEventArgs saea )
373
387
{
@@ -381,9 +395,8 @@ private static void OnSendCompleted(ISocket sender, ISocketAsyncEventArgs saea)
381
395
382
396
if ( saea . SocketError != SocketError . Success )
383
397
{
384
- connection . _sendContext . Promise . SetException ( new TransportException ( TransportError . WriteError ,
385
- new SocketException ( ( int ) saea . SocketError ) ) ) ;
386
- connection . CleanSend ( ) ;
398
+ connection . FaultSend ( new TransportException ( TransportError . WriteError ,
399
+ new SocketException ( ( int ) saea . SocketError ) ) ) ;
387
400
return ;
388
401
}
389
402
@@ -402,8 +415,7 @@ private static void OnSendCompleted(ISocket sender, ISocketAsyncEventArgs saea)
402
415
}
403
416
else
404
417
{
405
- connection . _sendContext . Promise . SetResult ( SuccessResult ) ;
406
- connection . CleanSend ( ) ;
418
+ connection . CompleteSend ( ) ;
407
419
}
408
420
}
409
421
}
@@ -430,8 +442,7 @@ private void LoopSend(int from, int count)
430
442
}
431
443
catch ( Exception ex )
432
444
{
433
- CleanSend ( ) ;
434
- _sendContext . Promise . SetException ( new TransportException ( TransportError . WriteError , ex ) ) ;
445
+ FaultSend ( new TransportException ( TransportError . WriteError , ex ) ) ;
435
446
}
436
447
}
437
448
0 commit comments