Kaynağa Gözat

Merge pull request #143 from csmith/master

Set the output stream on new output queues.
pull/145/head
Shane Mc Cormack 7 yıl önce
ebeveyn
işleme
e3b6080f46

+ 16
- 10
irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java Dosyayı Görüntüle

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

Loading…
İptal
Kaydet