|
@@ -50,6 +50,7 @@ import com.dmdirc.parser.irc.IRCReader.ReadLine;
|
50
|
50
|
import com.dmdirc.parser.irc.outputqueue.OutputQueue;
|
51
|
51
|
|
52
|
52
|
import java.io.IOException;
|
|
53
|
+import java.io.PrintWriter;
|
53
|
54
|
import java.net.InetAddress;
|
54
|
55
|
import java.net.Socket;
|
55
|
56
|
import java.net.URI;
|
|
@@ -205,11 +206,13 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
205
|
206
|
protected SocketState currentSocketState = SocketState.NULL;
|
206
|
207
|
/**
|
207
|
208
|
* The underlying socket used for reading/writing to the IRC server.
|
208
|
|
- * For normal sockets this will be the same as {@link #socket} but for SSL
|
|
209
|
+ * For normal sockets this will be the same as {@link #mySocket} but for SSL
|
209
|
210
|
* connections this will be the underlying {@link Socket} while
|
210
|
|
- * {@link #socket} will be an {@link SSLSocket}.
|
|
211
|
+ * {@link #mySocket} will be an {@link SSLSocket}.
|
211
|
212
|
*/
|
212
|
213
|
private Socket rawSocket;
|
|
214
|
+ /** Socket that we can do stuff to. */
|
|
215
|
+ private Socket mySocket;
|
213
|
216
|
/** Used for writing to the server. */
|
214
|
217
|
private final OutputQueue out;
|
215
|
218
|
/** The encoder to use to encode incoming lines. */
|
|
@@ -741,7 +744,6 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
741
|
744
|
|
742
|
745
|
rawSocket = getSocketFactory().createSocket(connectUri.getHost(), connectUri.getPort());
|
743
|
746
|
|
744
|
|
- final Socket socket;
|
745
|
747
|
if (getURI().getScheme().endsWith("s")) {
|
746
|
748
|
callDebugInfo(DEBUG_SOCKET, "Server is SSL.");
|
747
|
749
|
|
|
@@ -753,27 +755,27 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
753
|
755
|
sc.init(myKeyManagers, myTrustManager, new SecureRandom());
|
754
|
756
|
|
755
|
757
|
final SSLSocketFactory socketFactory = sc.getSocketFactory();
|
756
|
|
- socket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
|
|
758
|
+ mySocket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
|
757
|
759
|
.getPort(), false);
|
758
|
760
|
|
759
|
761
|
// Manually start a handshake so we get proper SSL errors here,
|
760
|
762
|
// and so that we can control the connection timeout
|
761
|
|
- final int timeout = socket.getSoTimeout();
|
762
|
|
- socket.setSoTimeout(10000);
|
763
|
|
- ((SSLSocket) socket).startHandshake();
|
764
|
|
- socket.setSoTimeout(timeout);
|
|
763
|
+ final int timeout = mySocket.getSoTimeout();
|
|
764
|
+ mySocket.setSoTimeout(10000);
|
|
765
|
+ ((SSLSocket) mySocket).startHandshake();
|
|
766
|
+ mySocket.setSoTimeout(timeout);
|
765
|
767
|
|
766
|
768
|
currentSocketState = SocketState.OPENING;
|
767
|
769
|
} else {
|
768
|
|
- socket = rawSocket;
|
|
770
|
+ mySocket = rawSocket;
|
769
|
771
|
}
|
770
|
772
|
|
771
|
773
|
callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
|
772
|
|
- out.setOutputStream(socket.getOutputStream());
|
|
774
|
+ out.setOutputStream(mySocket.getOutputStream());
|
773
|
775
|
out.setQueueEnabled(true);
|
774
|
776
|
currentSocketState = SocketState.OPEN;
|
775
|
777
|
callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
|
776
|
|
- in = new IRCReader(socket.getInputStream(), encoder);
|
|
778
|
+ in = new IRCReader(mySocket.getInputStream(), encoder);
|
777
|
779
|
callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
|
778
|
780
|
}
|
779
|
781
|
|
|
@@ -1765,17 +1767,22 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
1765
|
1767
|
|
1766
|
1768
|
@Override
|
1767
|
1769
|
public void quit(final String reason) {
|
1768
|
|
- sendString("QUIT", reason);
|
|
1770
|
+ // Don't attempt to send anything further.
|
|
1771
|
+ getOutputQueue().clearQueue();
|
|
1772
|
+ final String output = (reason == null || reason.isEmpty()) ? "QUIT" : "QUIT :" + reason;
|
|
1773
|
+ doSendString(output, QueuePriority.IMMEDIATE, true);
|
|
1774
|
+ // Don't bother queueing anything else.
|
|
1775
|
+ getOutputQueue().setDiscarding(true);
|
1769
|
1776
|
}
|
1770
|
1777
|
|
1771
|
1778
|
@Override
|
1772
|
1779
|
public void disconnect(final String message) {
|
1773
|
1780
|
super.disconnect(message);
|
1774
|
1781
|
if (currentSocketState == SocketState.OPENING || currentSocketState == SocketState.OPEN) {
|
1775
|
|
- currentSocketState = SocketState.CLOSING;
|
1776
|
1782
|
if (got001) {
|
1777
|
1783
|
quit(message);
|
1778
|
1784
|
}
|
|
1785
|
+ currentSocketState = SocketState.CLOSING;
|
1779
|
1786
|
}
|
1780
|
1787
|
|
1781
|
1788
|
try {
|