|
@@ -52,6 +52,7 @@ import com.dmdirc.parser.irc.events.IRCDataOutEvent;
|
52
|
52
|
import com.dmdirc.parser.irc.outputqueue.OutputQueue;
|
53
|
53
|
|
54
|
54
|
import java.io.IOException;
|
|
55
|
+import java.io.PrintWriter;
|
55
|
56
|
import java.net.InetAddress;
|
56
|
57
|
import java.net.Socket;
|
57
|
58
|
import java.net.URI;
|
|
@@ -207,9 +208,9 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
207
|
208
|
protected SocketState currentSocketState = SocketState.NULL;
|
208
|
209
|
/**
|
209
|
210
|
* The underlying socket used for reading/writing to the IRC server.
|
210
|
|
- * For normal sockets this will be the same as {@link #socket} but for SSL
|
|
211
|
+ * For normal sockets this will be the same as {@link #mySocket} but for SSL
|
211
|
212
|
* connections this will be the underlying {@link Socket} while
|
212
|
|
- * {@link #socket} will be an {@link SSLSocket}.
|
|
213
|
+ * {@link #mySocket} will be an {@link SSLSocket}.
|
213
|
214
|
*/
|
214
|
215
|
private Socket rawSocket;
|
215
|
216
|
/** Used for writing to the server. */
|
|
@@ -739,7 +740,7 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
739
|
740
|
|
740
|
741
|
rawSocket = getSocketFactory().createSocket(connectUri.getHost(), connectUri.getPort());
|
741
|
742
|
|
742
|
|
- final Socket socket;
|
|
743
|
+ final Socket mySocket;
|
743
|
744
|
if (getURI().getScheme().endsWith("s")) {
|
744
|
745
|
callDebugInfo(DEBUG_SOCKET, "Server is SSL.");
|
745
|
746
|
|
|
@@ -751,27 +752,27 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
751
|
752
|
sc.init(myKeyManagers, myTrustManager, new SecureRandom());
|
752
|
753
|
|
753
|
754
|
final SSLSocketFactory socketFactory = sc.getSocketFactory();
|
754
|
|
- socket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
|
|
755
|
+ mySocket = socketFactory.createSocket(rawSocket, getURI().getHost(), getURI()
|
755
|
756
|
.getPort(), false);
|
756
|
757
|
|
757
|
758
|
// Manually start a handshake so we get proper SSL errors here,
|
758
|
759
|
// and so that we can control the connection timeout
|
759
|
|
- final int timeout = socket.getSoTimeout();
|
760
|
|
- socket.setSoTimeout(10000);
|
761
|
|
- ((SSLSocket) socket).startHandshake();
|
762
|
|
- socket.setSoTimeout(timeout);
|
|
760
|
+ final int timeout = mySocket.getSoTimeout();
|
|
761
|
+ mySocket.setSoTimeout(10000);
|
|
762
|
+ ((SSLSocket) mySocket).startHandshake();
|
|
763
|
+ mySocket.setSoTimeout(timeout);
|
763
|
764
|
|
764
|
765
|
currentSocketState = SocketState.OPENING;
|
765
|
766
|
} else {
|
766
|
|
- socket = rawSocket;
|
|
767
|
+ mySocket = rawSocket;
|
767
|
768
|
}
|
768
|
769
|
|
769
|
770
|
callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket output stream PrintWriter");
|
770
|
|
- out.setOutputStream(socket.getOutputStream());
|
|
771
|
+ out.setOutputStream(mySocket.getOutputStream());
|
771
|
772
|
out.setQueueEnabled(true);
|
772
|
773
|
currentSocketState = SocketState.OPEN;
|
773
|
774
|
callDebugInfo(DEBUG_SOCKET, "\t-> Opening socket input stream BufferedReader");
|
774
|
|
- in = new IRCReader(socket.getInputStream(), encoder);
|
|
775
|
+ in = new IRCReader(mySocket.getInputStream(), encoder);
|
775
|
776
|
callDebugInfo(DEBUG_SOCKET, "\t-> Socket Opened");
|
776
|
777
|
}
|
777
|
778
|
|
|
@@ -1724,17 +1725,22 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
|
1724
|
1725
|
|
1725
|
1726
|
@Override
|
1726
|
1727
|
public void quit(final String reason) {
|
1727
|
|
- sendString("QUIT", reason);
|
|
1728
|
+ // Don't attempt to send anything further.
|
|
1729
|
+ getOutputQueue().clearQueue();
|
|
1730
|
+ final String output = (reason == null || reason.isEmpty()) ? "QUIT" : "QUIT :" + reason;
|
|
1731
|
+ doSendString(output, QueuePriority.IMMEDIATE, true);
|
|
1732
|
+ // Don't bother queueing anything else.
|
|
1733
|
+ getOutputQueue().setDiscarding(true);
|
1728
|
1734
|
}
|
1729
|
1735
|
|
1730
|
1736
|
@Override
|
1731
|
1737
|
public void disconnect(final String message) {
|
1732
|
1738
|
super.disconnect(message);
|
1733
|
1739
|
if (currentSocketState == SocketState.OPENING || currentSocketState == SocketState.OPEN) {
|
1734
|
|
- currentSocketState = SocketState.CLOSING;
|
1735
|
1740
|
if (got001) {
|
1736
|
1741
|
quit(message);
|
1737
|
1742
|
}
|
|
1743
|
+ currentSocketState = SocketState.CLOSING;
|
1738
|
1744
|
}
|
1739
|
1745
|
|
1740
|
1746
|
try {
|