@@ -27,6 +27,7 @@ public class WampSessionClient<TMessage> : IWampSessionClientExtended,
2727 private HelloDetails mSentDetails ;
2828
2929 private int mIsConnected = 0 ;
30+ private WampSessionCloseEventArgs mCloseEventArgs ;
3031
3132 private static HelloDetails GetDetails ( )
3233 {
@@ -98,7 +99,7 @@ public void Welcome(long session, WelcomeDetails details)
9899
99100 public void Abort ( AbortDetails details , string reason )
100101 {
101- RaiseConnectionBroken ( SessionCloseType . Abort , details , reason ) ;
102+ TrySetCloseEventArgs ( SessionCloseType . Abort , details , reason ) ;
102103 }
103104
104105 public void Goodbye ( GoodbyeDetails details , string reason )
@@ -108,34 +109,34 @@ public void Goodbye(GoodbyeDetails details, string reason)
108109 mServerProxy . Goodbye ( new GoodbyeDetails ( ) , WampErrors . GoodbyeAndOut ) ;
109110 }
110111
111- RaiseConnectionBroken ( SessionCloseType . Goodbye , details , reason ) ;
112+ TrySetCloseEventArgs ( SessionCloseType . Goodbye , details , reason ) ;
112113 }
113114
114- private void RaiseConnectionBroken ( SessionCloseType sessionCloseType , GoodbyeAbortDetails details , string reason )
115+ private void RaiseConnectionBroken ( )
115116 {
116- bool connectionBrokenRaised = mConnectionBrokenRaised ;
117+ TrySetCloseEventArgs ( SessionCloseType . Disconnection ) ;
117118
118- mConnectionBrokenRaised = true ;
119+ WampSessionCloseEventArgs closeEventArgs = mCloseEventArgs ;
119120
120- WampSessionCloseEventArgs closeEventArgs = new WampSessionCloseEventArgs
121- ( sessionCloseType , mSession ,
122- details ,
123- reason ) ;
124-
125- SetOpenTaskErrorIfNeeded ( new WampConnectionBrokenException ( closeEventArgs ) ) ;
121+ SetOpenTaskErrorIfNeeded ( new WampConnectionBrokenException ( mCloseEventArgs ) ) ;
126122
127- if ( sessionCloseType == SessionCloseType . Disconnection )
128- {
129- Interlocked . CompareExchange ( ref mIsConnected , 0 , 1 ) ;
123+ Interlocked . CompareExchange ( ref mIsConnected , 0 , 1 ) ;
124+ mOpenTask = new TaskCompletionSource < bool > ( ) ;
125+ mCloseEventArgs = null ;
130126
131- mOpenTask = new TaskCompletionSource < bool > ( ) ;
132-
133- mConnectionBrokenRaised = false ;
134- }
127+ OnConnectionBroken ( closeEventArgs ) ;
128+ }
135129
136- if ( ! connectionBrokenRaised )
130+ private void TrySetCloseEventArgs ( SessionCloseType sessionCloseType ,
131+ GoodbyeAbortDetails details = null ,
132+ string reason = null )
133+ {
134+ if ( mCloseEventArgs == null )
137135 {
138- OnConnectionBroken ( closeEventArgs ) ;
136+ mCloseEventArgs = new WampSessionCloseEventArgs
137+ ( sessionCloseType , mSession ,
138+ details ,
139+ reason ) ;
139140 }
140141 }
141142
@@ -195,11 +196,7 @@ public void OnConnectionOpen()
195196
196197 public void OnConnectionClosed ( )
197198 {
198- SetOpenTaskErrorIfNeeded ( new Exception ( "Connection closed before connection established." ) ) ;
199-
200- RaiseConnectionBroken ( SessionCloseType . Disconnection ,
201- null ,
202- null ) ;
199+ RaiseConnectionBroken ( ) ;
203200 }
204201
205202 public void OnConnectionError ( Exception exception )
0 commit comments