Explorar el Código

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 hace 14 años
padre
commit
ae86827c73

+ 14
- 24
src/com/dmdirc/parser/irc/IRCParser.java Ver fichero

@@ -305,23 +305,10 @@ public class IRCParser implements SecureParser, Runnable {
305 305
      *
306 306
      * @return the current OutputQueue
307 307
      */
308
-    public OutputQueue getOut() {
308
+    public OutputQueue getOutputQueue() {
309 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 313
      * Get the current Value of bindIP.
327 314
      *
@@ -409,7 +396,7 @@ public class IRCParser implements SecureParser, Runnable {
409 396
     public ProcessingManager getProcessingManager() { return myProcessingManager;    }
410 397
 
411 398
     /** {@inheritDoc} */
412
-        @Override
399
+    @Override
413 400
     public CallbackManager<IRCParser> getCallbackManager() { return myCallbackManager;    }
414 401
 
415 402
     /**
@@ -680,7 +667,7 @@ public class IRCParser implements SecureParser, Runnable {
680 667
 
681 668
             final Proxy.Type proxyType = Proxy.Type.SOCKS;
682 669
             socket = new Socket(new Proxy(proxyType, new InetSocketAddress(server.getProxyHost(), server.getProxyPort())));
683
-            currentSocketState = SocketState.OPEN;
670
+            currentSocketState = SocketState.OPENING;
684 671
             if (server.getProxyUser() != null && !server.getProxyUser().isEmpty()) {
685 672
                 IRCAuthenticator.getIRCAuthenticator().addAuthentication(server);
686 673
             }
@@ -699,7 +686,7 @@ public class IRCParser implements SecureParser, Runnable {
699 686
                     }
700 687
                 }
701 688
 
702
-                currentSocketState = SocketState.OPEN;
689
+                currentSocketState = SocketState.OPENING;
703 690
                 socket.connect(new InetSocketAddress(server.getHost(), server.getPort()));
704 691
             }
705 692
         }
@@ -729,12 +716,13 @@ public class IRCParser implements SecureParser, Runnable {
729 716
                 }
730 717
             }
731 718
 
732
-            currentSocketState = SocketState.OPEN;
719
+            currentSocketState = SocketState.OPENING;
733 720
         }
734 721
 
735 722
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
736 723
         out.setOutputStream(socket.getOutputStream());
737 724
         out.setQueueEnabled(true);
725
+        currentSocketState = SocketState.OPEN;
738 726
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
739 727
         in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
740 728
         callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
@@ -834,7 +822,7 @@ public class IRCParser implements SecureParser, Runnable {
834 822
     /** {@inheritDoc} */
835 823
         @Override
836 824
     public int getLocalPort() {
837
-        if (currentSocketState == SocketState.OPEN) {
825
+        if (currentSocketState == SocketState.OPENING || currentSocketState == SocketState.OPEN) {
838 826
             return socket.getLocalPort();
839 827
         } else {
840 828
             return 0;
@@ -1636,10 +1624,10 @@ public class IRCParser implements SecureParser, Runnable {
1636 1624
     /** {@inheritDoc} */
1637 1625
     @Override
1638 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 1632
         try {
1645 1633
             if (socket != null) { socket.close(); }
@@ -1849,7 +1837,9 @@ public class IRCParser implements SecureParser, Runnable {
1849 1837
      * @param timer The timer that called this.
1850 1838
      */
1851 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 1843
             pingTimerSem.acquireUninterruptibly();
1854 1844
             if (pingTimer != null && pingTimer.equals(timer)) {
1855 1845
                 pingTimer.cancel();

+ 6
- 5
src/com/dmdirc/parser/irc/SocketState.java Ver fichero

@@ -30,13 +30,14 @@ package com.dmdirc.parser.irc;
30 30
  */
31 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 37
     /** Socket is closing, don't process any more lines. */
36 38
     CLOSING,
37 39
     /** Socket is closed. */
38 40
     CLOSED,
39
-    /** Socket is Open. */
40
-    OPEN;
41
-
41
+    /** Socket is not created yet. */
42
+    NULL;
42 43
 }

Loading…
Cancelar
Guardar