Browse Source

Add SocketState.OPENING as an intermediary state between the socket being created, and the OutputStream being passed to the OutputQueue

Remove the ability to change OutputQueue due to confusion, just allow changing the OutputHandler.
tags/0.6.3
Shane Mc Cormack 15 years ago
parent
commit
ae86827c73

+ 14
- 24
src/com/dmdirc/parser/irc/IRCParser.java View File

305
      *
305
      *
306
      * @return the current OutputQueue
306
      * @return the current OutputQueue
307
      */
307
      */
308
-    public OutputQueue getOut() {
308
+    public OutputQueue getOutputQueue() {
309
         return out;
309
         return out;
310
     }
310
     }
311
 
311
 
312
-    /**
313
-     * Set the OutputQueue
314
-     *
315
-     * @param out the new current OutputQueue
316
-     */
317
-    public void setOut(final OutputQueue out) throws IRCParserException {
318
-        if (currentSocketState == SocketState.CLOSED) {
319
-            this.out = out;
320
-        } else {
321
-            throw new IRCParserException("OutputQueue can only be changed when disconnected.");
322
-        }
323
-    }
324
-
325
     /**
312
     /**
326
      * Get the current Value of bindIP.
313
      * Get the current Value of bindIP.
327
      *
314
      *
409
     public ProcessingManager getProcessingManager() { return myProcessingManager;    }
396
     public ProcessingManager getProcessingManager() { return myProcessingManager;    }
410
 
397
 
411
     /** {@inheritDoc} */
398
     /** {@inheritDoc} */
412
-        @Override
399
+    @Override
413
     public CallbackManager<IRCParser> getCallbackManager() { return myCallbackManager;    }
400
     public CallbackManager<IRCParser> getCallbackManager() { return myCallbackManager;    }
414
 
401
 
415
     /**
402
     /**
680
 
667
 
681
             final Proxy.Type proxyType = Proxy.Type.SOCKS;
668
             final Proxy.Type proxyType = Proxy.Type.SOCKS;
682
             socket = new Socket(new Proxy(proxyType, new InetSocketAddress(server.getProxyHost(), server.getProxyPort())));
669
             socket = new Socket(new Proxy(proxyType, new InetSocketAddress(server.getProxyHost(), server.getProxyPort())));
683
-            currentSocketState = SocketState.OPEN;
670
+            currentSocketState = SocketState.OPENING;
684
             if (server.getProxyUser() != null && !server.getProxyUser().isEmpty()) {
671
             if (server.getProxyUser() != null && !server.getProxyUser().isEmpty()) {
685
                 IRCAuthenticator.getIRCAuthenticator().addAuthentication(server);
672
                 IRCAuthenticator.getIRCAuthenticator().addAuthentication(server);
686
             }
673
             }
699
                     }
686
                     }
700
                 }
687
                 }
701
 
688
 
702
-                currentSocketState = SocketState.OPEN;
689
+                currentSocketState = SocketState.OPENING;
703
                 socket.connect(new InetSocketAddress(server.getHost(), server.getPort()));
690
                 socket.connect(new InetSocketAddress(server.getHost(), server.getPort()));
704
             }
691
             }
705
         }
692
         }
729
                 }
716
                 }
730
             }
717
             }
731
 
718
 
732
-            currentSocketState = SocketState.OPEN;
719
+            currentSocketState = SocketState.OPENING;
733
         }
720
         }
734
 
721
 
735
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
722
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
736
         out.setOutputStream(socket.getOutputStream());
723
         out.setOutputStream(socket.getOutputStream());
737
         out.setQueueEnabled(true);
724
         out.setQueueEnabled(true);
725
+        currentSocketState = SocketState.OPEN;
738
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
726
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
739
         in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
727
         in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
740
         callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
728
         callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
834
     /** {@inheritDoc} */
822
     /** {@inheritDoc} */
835
         @Override
823
         @Override
836
     public int getLocalPort() {
824
     public int getLocalPort() {
837
-        if (currentSocketState == SocketState.OPEN) {
825
+        if (currentSocketState == SocketState.OPENING || currentSocketState == SocketState.OPEN) {
838
             return socket.getLocalPort();
826
             return socket.getLocalPort();
839
         } else {
827
         } else {
840
             return 0;
828
             return 0;
1636
     /** {@inheritDoc} */
1624
     /** {@inheritDoc} */
1637
     @Override
1625
     @Override
1638
     public void disconnect(final String message) {
1626
     public void disconnect(final String message) {
1639
-                if (currentSocketState == SocketState.OPEN) {
1640
-                        currentSocketState = SocketState.CLOSING;
1641
-                        if (got001) { quit(message); }
1642
-                }
1627
+        if (currentSocketState == SocketState.OPENING || currentSocketState == SocketState.OPEN) {
1628
+            currentSocketState = SocketState.CLOSING;
1629
+            if (got001) { quit(message); }
1630
+        }
1643
 
1631
 
1644
         try {
1632
         try {
1645
             if (socket != null) { socket.close(); }
1633
             if (socket != null) { socket.close(); }
1849
      * @param timer The timer that called this.
1837
      * @param timer The timer that called this.
1850
      */
1838
      */
1851
     protected void pingTimerTask(final Timer timer) {
1839
     protected void pingTimerTask(final Timer timer) {
1852
-        if (!getCheckServerPing()) {
1840
+        // If user no longer wants server ping to be checked, or the socket is
1841
+        // closed then cancel the time and do nothing else.
1842
+        if (!getCheckServerPing() || getSocketState() != SocketState.OPEN) {
1853
             pingTimerSem.acquireUninterruptibly();
1843
             pingTimerSem.acquireUninterruptibly();
1854
             if (pingTimer != null && pingTimer.equals(timer)) {
1844
             if (pingTimer != null && pingTimer.equals(timer)) {
1855
                 pingTimer.cancel();
1845
                 pingTimer.cancel();

+ 6
- 5
src/com/dmdirc/parser/irc/SocketState.java View File

30
  */
30
  */
31
 public enum SocketState {
31
 public enum SocketState {
32
 
32
 
33
-    /** Socket is not created yet. */
34
-    NULL,
33
+    /** Socket is Open. */
34
+    OPEN,
35
+    /** Socket is Opening. */
36
+    OPENING,
35
     /** Socket is closing, don't process any more lines. */
37
     /** Socket is closing, don't process any more lines. */
36
     CLOSING,
38
     CLOSING,
37
     /** Socket is closed. */
39
     /** Socket is closed. */
38
     CLOSED,
40
     CLOSED,
39
-    /** Socket is Open. */
40
-    OPEN;
41
-
41
+    /** Socket is not created yet. */
42
+    NULL;
42
 }
43
 }

Loading…
Cancel
Save