Browse Source

Don't allow resetting state whilst socketClose events are still occuring.

pull/102/head
Shane Mc Cormack 8 years ago
parent
commit
a23c571fdb
1 changed files with 8 additions and 0 deletions
  1. 8
    0
      irc/src/com/dmdirc/parser/irc/IRCParser.java

+ 8
- 0
irc/src/com/dmdirc/parser/irc/IRCParser.java View File

231
     private final Map<String, CapabilityState> capabilities = new HashMap<>();
231
     private final Map<String, CapabilityState> capabilities = new HashMap<>();
232
     /** Handler for whois responses. */
232
     /** Handler for whois responses. */
233
     private final WhoisResponseHandler whoisHandler;
233
     private final WhoisResponseHandler whoisHandler;
234
+    /** Semaphore for calls to resetState. */
235
+    private final Semaphore resetStateSem = new Semaphore(1);
234
 
236
 
235
     /**
237
     /**
236
      * Default constructor, ServerInfo and MyInfo need to be added separately (using IRC.me and IRC.server).
238
      * Default constructor, ServerInfo and MyInfo need to be added separately (using IRC.me and IRC.server).
590
      * Callback to all objects implementing the SocketClosed Callback.
592
      * Callback to all objects implementing the SocketClosed Callback.
591
      */
593
      */
592
     protected void callSocketClosed() {
594
     protected void callSocketClosed() {
595
+        // Don't allow state resetting whilst there may be handlers requiring
596
+        // state.
597
+        resetStateSem.acquireUninterruptibly();
593
         getCallbackManager().publish(new SocketCloseEvent(this, new Date()));
598
         getCallbackManager().publish(new SocketCloseEvent(this, new Date()));
599
+        resetStateSem.release();
594
     }
600
     }
595
 
601
 
596
     /**
602
     /**
643
     //---------------------------------------------------------------------------
649
     //---------------------------------------------------------------------------
644
     /** Reset internal state (use before doConnect). */
650
     /** Reset internal state (use before doConnect). */
645
     private void resetState() {
651
     private void resetState() {
652
+        resetStateSem.acquireUninterruptibly();
646
         // Reset General State info
653
         // Reset General State info
647
         got001 = false;
654
         got001 = false;
648
         post005 = false;
655
         post005 = false;
673
         setEncoding(IRCEncoding.RFC1459);
680
         setEncoding(IRCEncoding.RFC1459);
674
 
681
 
675
         whoisHandler.stop();
682
         whoisHandler.stop();
683
+        resetStateSem.release();
676
     }
684
     }
677
 
685
 
678
     /**
686
     /**

Loading…
Cancel
Save