@@ -194,7 +194,7 @@ public void attach(CompletionListener listener) throws AblyException {
194194
195195 void attach (boolean forceReattach , CompletionListener listener ) {
196196 clearAttachTimers ();
197- attachWithTimeout (forceReattach , listener );
197+ attachWithTimeout (forceReattach , listener , null );
198198 }
199199
200200 /**
@@ -217,7 +217,7 @@ synchronized void transferQueuedPresenceMessages(List<QueuedMessage> messagesToT
217217
218218 private boolean attachResume ;
219219
220- private void attachImpl (final boolean forceReattach , final CompletionListener listener ) throws AblyException {
220+ private void attachImpl (final boolean forceReattach , final CompletionListener listener , ErrorInfo reattachmentReason ) throws AblyException {
221221 Log .v (TAG , "attach(); channel = " + name );
222222 if (!forceReattach ) {
223223 /* check preconditions */
@@ -249,7 +249,7 @@ private void attachImpl(final boolean forceReattach, final CompletionListener li
249249 if (listener != null ) {
250250 on (new ChannelStateCompletionListener (listener , ChannelState .attached , ChannelState .failed ));
251251 }
252- setState (ChannelState .attaching , null );
252+ setState (ChannelState .attaching , reattachmentReason );
253253 return ;
254254 }
255255
@@ -277,7 +277,7 @@ private void attachImpl(final boolean forceReattach, final CompletionListener li
277277 attachMessage .setFlag (Flag .attach_resume );
278278 }
279279
280- setState (ChannelState .attaching , null );
280+ setState (ChannelState .attaching , reattachmentReason );
281281 connectionManager .send (attachMessage , true , null );
282282 } catch (AblyException e ) {
283283 throw e ;
@@ -470,14 +470,14 @@ synchronized private void clearAttachTimers() {
470470 }
471471
472472 private void attachWithTimeout (final CompletionListener listener ) throws AblyException {
473- this .attachWithTimeout (false , listener );
473+ this .attachWithTimeout (false , listener , null );
474474 }
475475
476476 /**
477477 * Attach channel, if not attached within timeout set state to suspended and
478478 * set up timer to reattach it later
479479 */
480- synchronized private void attachWithTimeout (final boolean forceReattach , final CompletionListener listener ) {
480+ synchronized private void attachWithTimeout (final boolean forceReattach , final CompletionListener listener , ErrorInfo reattachmentReason ) {
481481 checkChannelIsNotReleased ();
482482 Timer currentAttachTimer ;
483483 try {
@@ -502,7 +502,7 @@ public void onError(ErrorInfo reason) {
502502 clearAttachTimers ();
503503 callCompletionListenerError (listener , reason );
504504 }
505- });
505+ }, reattachmentReason );
506506 } catch (AblyException e ) {
507507 attachTimer = null ;
508508 callCompletionListenerError (listener , e .errorInfo );
@@ -1303,7 +1303,7 @@ void onChannelMessage(ProtocolMessage msg) {
13031303 case suspended :
13041304 /* Unexpected detach, reattach immediately as per RTL13a */
13051305 Log .v (TAG , String .format (Locale .ROOT , "Server initiated detach for channel %s; attempting reattach" , name ));
1306- attachWithTimeout (true , null );
1306+ attachWithTimeout (true , null , msg . error );
13071307 break ;
13081308 case attaching :
13091309 /* RTL13b says we need to be suspended, but continue to retry */
0 commit comments