@@ -75,17 +75,20 @@ internal ITransport Open(string hostname, ITransport transport)
7575 this . OnHeader ( myHeader , theirHeader ) ;
7676
7777 SaslCode code = SaslCode . SysTemp ;
78- while ( true )
78+ bool shouldContinue = true ;
79+ while ( shouldContinue )
7980 {
8081 ByteBuffer buffer = Reader . ReadFrameBuffer ( transport , new byte [ 4 ] , MaxFrameSize ) ;
8182 if ( buffer == null )
8283 {
8384 throw new OperationCanceledException ( Fx . Format ( SRAmqp . TransportClosed , transport . GetType ( ) . Name ) ) ;
8485 }
8586
86- if ( ! this . OnFrame ( hostname , transport , buffer , out code ) )
87+ DescribedList response = null ;
88+ shouldContinue = this . OnFrame ( hostname , buffer , out response , out code ) ;
89+ if ( response != null )
8790 {
88- break ;
91+ SendCommand ( transport , response ) ;
8992 }
9093 }
9194
@@ -113,7 +116,7 @@ internal ProtocolHeader Start(ITransport transport, DescribedList command)
113116
114117 if ( command != null )
115118 {
116- this . SendCommand ( transport , command ) ;
119+ SendCommand ( transport , command ) ;
117120 }
118121
119122 return myHeader ;
@@ -129,14 +132,15 @@ internal void OnHeader(ProtocolHeader myHeader, ProtocolHeader theirHeader)
129132 }
130133 }
131134
132- internal bool OnFrame ( string hostname , ITransport transport , ByteBuffer buffer , out SaslCode code )
135+ internal bool OnFrame ( string hostname , ByteBuffer buffer , out DescribedList response , out SaslCode code )
133136 {
134137 ushort channel ;
135138 DescribedList command ;
136139 Frame . Decode ( buffer , out channel , out command ) ;
137140 Trace . WriteLine ( TraceLevel . Frame , "RECV {0}" , command ) ;
138141
139142 bool shouldContinue = true ;
143+ response = null ;
140144 if ( command . Descriptor . Code == Codec . SaslOutcome . Code )
141145 {
142146 code = ( ( SaslOutcome ) command ) . Code ;
@@ -162,24 +166,16 @@ internal bool OnFrame(string hostname, ITransport transport, ByteBuffer buffer,
162166 throw new AmqpException ( ErrorCode . NotImplemented , mechanisms . ToString ( ) ) ;
163167 }
164168
165- DescribedList init = this . GetStartCommand ( hostname ) ;
166- if ( init != null )
167- {
168- this . SendCommand ( transport , init ) ;
169- }
169+ response = this . GetStartCommand ( hostname ) ;
170170 }
171171 else
172172 {
173173 code = SaslCode . Ok ;
174- DescribedList response = this . OnCommand ( command ) ;
175- if ( response != null )
174+ response = this . OnCommand ( command ) ;
175+ if ( response != null && response . Descriptor . Code == Codec . SaslOutcome . Code )
176176 {
177- this . SendCommand ( transport , response ) ;
178- if ( response . Descriptor . Code == Codec . SaslOutcome . Code )
179- {
180- code = ( ( SaslOutcome ) response ) . Code ;
181- shouldContinue = false ;
182- }
177+ code = ( ( SaslOutcome ) response ) . Code ;
178+ shouldContinue = false ;
183179 }
184180 }
185181
@@ -231,7 +227,7 @@ protected virtual bool Match(Symbol mechanism)
231227 /// <returns>A SASL command as a response to the incoming command.</returns>
232228 protected abstract DescribedList OnCommand ( DescribedList command ) ;
233229
234- void SendCommand ( ITransport transport , DescribedList command )
230+ internal static void SendCommand ( ITransport transport , DescribedList command )
235231 {
236232 ByteBuffer buffer = new ByteBuffer ( Frame . CmdBufferSize , true ) ;
237233 Frame . Encode ( buffer , FrameType . Sasl , 0 , command ) ;
0 commit comments