@@ -3757,14 +3757,10 @@ public bool AcceptAsync(SocketAsyncEventArgs e)
37573757 SafeCloseSocket acceptHandle ;
37583758 e . AcceptSocket = GetOrCreateAcceptSocket ( e . AcceptSocket , true , "AcceptSocket" , out acceptHandle ) ;
37593759
3760- // Prepare for the native call.
3761- e . StartOperationCommon ( this ) ;
3760+ // Prepare for and make the native call.
3761+ e . StartOperationCommon ( this , SocketAsyncOperation . Accept ) ;
37623762 e . StartOperationAccept ( ) ;
3763-
3764- // Local variables for sync completion.
37653763 SocketError socketError = SocketError . Success ;
3766-
3767- // Make the native call.
37683764 try
37693765 {
37703766 socketError = e . DoOperationAccept ( this , _handle , acceptHandle ) ;
@@ -3825,8 +3821,8 @@ public bool ConnectAsync(SocketAsyncEventArgs e)
38253821
38263822 MultipleConnectAsync multipleConnectAsync = new SingleSocketMultipleConnectAsync ( this , true ) ;
38273823
3828- e . StartOperationCommon ( this ) ;
3829- e . StartOperationWrapperConnect ( multipleConnectAsync ) ;
3824+ e . StartOperationCommon ( this , SocketAsyncOperation . Connect ) ;
3825+ e . StartOperationConnect ( multipleConnectAsync ) ;
38303826
38313827 pending = multipleConnectAsync . StartConnectAsync ( e , dnsEP ) ;
38323828 }
@@ -3863,7 +3859,7 @@ public bool ConnectAsync(SocketAsyncEventArgs e)
38633859 }
38643860
38653861 // Prepare for the native call.
3866- e . StartOperationCommon ( this ) ;
3862+ e . StartOperationCommon ( this , SocketAsyncOperation . Connect ) ;
38673863 e . StartOperationConnect ( ) ;
38683864
38693865 // Make the native call.
@@ -3926,8 +3922,8 @@ public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType
39263922 multipleConnectAsync = new SingleSocketMultipleConnectAsync ( attemptSocket , false ) ;
39273923 }
39283924
3929- e . StartOperationCommon ( attemptSocket ) ;
3930- e . StartOperationWrapperConnect ( multipleConnectAsync ) ;
3925+ e . StartOperationCommon ( attemptSocket , SocketAsyncOperation . Connect ) ;
3926+ e . StartOperationConnect ( multipleConnectAsync ) ;
39313927
39323928 pending = multipleConnectAsync . StartConnectAsync ( e , dnsEP ) ;
39333929 }
@@ -3960,10 +3956,8 @@ public bool DisconnectAsync(SocketAsyncEventArgs e)
39603956 throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
39613957 }
39623958
3963- // Prepare for the native call.
3964- e . StartOperationCommon ( this ) ;
3965- e . StartOperationDisconnect ( ) ;
3966-
3959+ // Prepare for and make the native call.
3960+ e . StartOperationCommon ( this , SocketAsyncOperation . Disconnect ) ;
39673961 SocketError socketError = SocketError . Success ;
39683962 try
39693963 {
@@ -3995,14 +3989,9 @@ public bool ReceiveAsync(SocketAsyncEventArgs e)
39953989 throw new ArgumentNullException ( nameof ( e ) ) ;
39963990 }
39973991
3998- // Prepare for the native call.
3999- e . StartOperationCommon ( this ) ;
4000- e . StartOperationReceive ( ) ;
4001-
4002- // Local vars for sync completion of native call.
3992+ // Prepare for and make the native call.
3993+ e . StartOperationCommon ( this , SocketAsyncOperation . Receive ) ;
40033994 SocketError socketError ;
4004-
4005- // Wrap native methods with try/catch so event args object can be cleaned up.
40063995 try
40073996 {
40083997 socketError = e . DoOperationReceive ( _handle , out _ ) ;
@@ -4053,13 +4042,9 @@ public bool ReceiveFromAsync(SocketAsyncEventArgs e)
40534042 // e.m_SocketAddres for Create to work later.
40544043 e . RemoteEndPoint = endPointSnapshot ;
40554044
4056- // Prepare for the native call.
4057- e . StartOperationCommon ( this ) ;
4058- e . StartOperationReceiveFrom ( ) ;
4059-
4060- // Make the native call.
4045+ // Prepare for and make the native call.
4046+ e . StartOperationCommon ( this , SocketAsyncOperation . ReceiveFrom ) ;
40614047 SocketError socketError ;
4062-
40634048 try
40644049 {
40654050 socketError = e . DoOperationReceiveFrom ( _handle , out _ ) ;
@@ -4112,13 +4097,9 @@ public bool ReceiveMessageFromAsync(SocketAsyncEventArgs e)
41124097
41134098 SetReceivingPacketInformation ( ) ;
41144099
4115- // Prepare for the native call.
4116- e . StartOperationCommon ( this ) ;
4117- e . StartOperationReceiveMessageFrom ( ) ;
4118-
4119- // Make the native call.
4100+ // Prepare for and make the native call.
4101+ e . StartOperationCommon ( this , SocketAsyncOperation . ReceiveMessageFrom ) ;
41204102 SocketError socketError ;
4121-
41224103 try
41234104 {
41244105 socketError = e . DoOperationReceiveMessageFrom ( this , _handle ) ;
@@ -4149,14 +4130,9 @@ public bool SendAsync(SocketAsyncEventArgs e)
41494130 throw new ArgumentNullException ( nameof ( e ) ) ;
41504131 }
41514132
4152- // Prepare for the native call.
4153- e . StartOperationCommon ( this ) ;
4154- e . StartOperationSend ( ) ;
4155-
4156- // Local vars for sync completion of native call.
4133+ // Prepare for and make the native call.
4134+ e . StartOperationCommon ( this , SocketAsyncOperation . Send ) ;
41574135 SocketError socketError ;
4158-
4159- // Wrap native methods with try/catch so event args object can be cleaned up.
41604136 try
41614137 {
41624138 socketError = e . DoOperationSend ( _handle ) ;
@@ -4196,33 +4172,18 @@ public bool SendPacketsAsync(SocketAsyncEventArgs e)
41964172 throw new NotSupportedException ( SR . net_notconnected ) ;
41974173 }
41984174
4199- // Prepare for the native call.
4200- e . StartOperationCommon ( this ) ;
4201- e . StartOperationSendPackets ( ) ;
4202-
4203- // Make the native call.
4175+ // Prepare for and make the native call.
4176+ e . StartOperationCommon ( this , SocketAsyncOperation . SendPackets ) ;
42044177 SocketError socketError ;
4205-
4206- Debug . Assert ( e . SendPacketsDescriptorCount != null ) ;
4207-
4208- if ( e . SendPacketsDescriptorCount > 0 )
4178+ try
42094179 {
4210- try
4211- {
4212- socketError = e . DoOperationSendPackets ( this , _handle ) ;
4213- }
4214- catch ( Exception )
4215- {
4216- // Clear in-use flag on event args object.
4217- e . Complete ( ) ;
4218- throw ;
4219- }
4180+ socketError = e . DoOperationSendPackets ( this , _handle ) ;
42204181 }
4221- else
4182+ catch ( Exception )
42224183 {
4223- // No buffers or files to send .
4224- e . FinishOperationSyncSuccess ( 0 , SocketFlags . None ) ;
4225- socketError = SocketError . Success ;
4184+ // Clear in-use flag on event args object .
4185+ e . Complete ( ) ;
4186+ throw ;
42264187 }
42274188
42284189 bool pending = ( socketError == SocketError . IOPending ) ;
@@ -4252,14 +4213,9 @@ public bool SendToAsync(SocketAsyncEventArgs e)
42524213 EndPoint endPointSnapshot = e . RemoteEndPoint ;
42534214 e . _socketAddress = SnapshotAndSerialize ( ref endPointSnapshot ) ;
42544215
4255- // Prepare for the native call.
4256- e . StartOperationCommon ( this ) ;
4257- e . StartOperationSendTo ( ) ;
4258-
4259- // Make the native call.
4216+ // Prepare for and make the native call.
4217+ e . StartOperationCommon ( this , SocketAsyncOperation . SendTo ) ;
42604218 SocketError socketError ;
4261-
4262- // Wrap native methods with try/catch so event args object can be cleaned up.
42634219 try
42644220 {
42654221 socketError = e . DoOperationSendTo ( _handle ) ;
0 commit comments