Explorar el Código

Merge pull request #143 from csmith/master

Set the output stream on new output queues.
pull/145/head
Shane Mc Cormack hace 7 años
padre
commit
e3b6080f46
Se han modificado 1 ficheros con 16 adiciones y 10 borrados
  1. 16
    10
      irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java

+ 16
- 10
irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java Ver fichero

@@ -212,6 +212,8 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
212 212
      * wrapped, and should therefore not be used to send or receive data.
213 213
      */
214 214
     private Socket rawSocket;
215
+    /** The socket connected to the IRC server, used for sending or receiving data. */
216
+    private Socket socket;
215 217
     /** Used for writing to the server. */
216 218
     private OutputQueue out;
217 219
     /** The encoder to use to encode incoming lines. */
@@ -309,9 +311,14 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
309 311
      *
310 312
      * @param queue The queue to be added.
311 313
      */
312
-    public void setOutputQueue(final OutputQueue queue) {
314
+    public void setOutputQueue(final OutputQueue queue) throws IOException {
313 315
         checkNotNull(queue);
314 316
         out.clearQueue();
317
+
318
+        if (socket != null) {
319
+            queue.setOutputStream(socket.getOutputStream());
320
+        }
321
+
315 322
         out = queue;
316 323
     }
317 324
 
@@ -750,7 +757,6 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
750 757
 
751 758
         rawSocket = getSocketFactory().createSocket(connectUri.getHost(), connectUri.getPort());
752 759
 
753
-        final Socket mySocket;
754 760
         if (getURI().getScheme().endsWith("s")) {
755 761
             callDebugInfo(DEBUG_SOCKET, "Server is SSL.");
756 762
 
@@ -762,27 +768,27 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
762 768
             sc.init(myKeyManagers, myTrustManager, new SecureRandom());
763 769
 
764 770
             final SSLSocketFactory socketFactory = sc.getSocketFactory();
765
-            mySocket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
771
+            socket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
766 772
                     .getPort(), false);
767 773
 
768 774
             // Manually start a handshake so we get proper SSL errors here,
769 775
             // and so that we can control the connection timeout
770
-            final int timeout = mySocket.getSoTimeout();
771
-            mySocket.setSoTimeout(10000);
772
-            ((SSLSocket) mySocket).startHandshake();
773
-            mySocket.setSoTimeout(timeout);
776
+            final int timeout = socket.getSoTimeout();
777
+            socket.setSoTimeout(10000);
778
+            ((SSLSocket) socket).startHandshake();
779
+            socket.setSoTimeout(timeout);
774 780
 
775 781
             currentSocketState = SocketState.OPENING;
776 782
         } else {
777
-            mySocket = rawSocket;
783
+            socket = rawSocket;
778 784
         }
779 785
 
780 786
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
781
-        out.setOutputStream(mySocket.getOutputStream());
787
+        out.setOutputStream(socket.getOutputStream());
782 788
         out.setQueueEnabled(true);
783 789
         currentSocketState = SocketState.OPEN;
784 790
         callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
785
-        in = new IRCReader(mySocket.getInputStream(), encoder);
791
+        in = new IRCReader(socket.getInputStream(), encoder);
786 792
         callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
787 793
     }
788 794
 

Loading…
Cancelar
Guardar