X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Firc%2FConnection.java;h=336fdae2ea31b7b1ed1777ba756aaabdeb6e13b2;hb=5c5094e0a1eace0ff43d032b550d872ea2e45050;hp=b67b8db8ef5fba0c7926d1d41a9f0dadbe4d70dd;hpb=d72a8d36fc0d97c3ddba049b6fa85c3a69fd7118;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index b67b8db..336fdae 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.net.SocketFactory; @@ -59,6 +60,7 @@ import net.pterodactylus.irc.event.NicknameInUseReceived; import net.pterodactylus.irc.event.NoNicknameGivenReceived; import net.pterodactylus.irc.event.PrivateMessageReceived; import net.pterodactylus.irc.event.PrivateNoticeReceived; +import net.pterodactylus.irc.event.ReplyReceived; import net.pterodactylus.irc.event.UnknownReplyReceived; import net.pterodactylus.irc.util.RandomNickname; import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream; @@ -324,7 +326,9 @@ public class Connection extends AbstractExecutionThreadService implements Servic * if an I/O error occurs */ public void close() throws IOException { - connectionHandler.close(); + if (connectionHandler != null) { + connectionHandler.close(); + } } // @@ -343,6 +347,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic /* connect to remote socket. */ try { Socket socket = socketFactory.createSocket(hostname, port); + socket.setSoTimeout((int) TimeUnit.MINUTES.toMillis(3)); connectionHandler = new ConnectionHandler(socket.getInputStream(), socket.getOutputStream()); /* register connection. */ @@ -373,6 +378,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic while (connected) { Reply reply = connectionHandler.readReply(); + eventBus.post(new ReplyReceived(this, reply)); logger.finest(String.format("<< %s", reply)); String command = reply.command(); List parameters = reply.parameters(); @@ -553,7 +559,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic } } else if (messageWords[1].equalsIgnoreCase("ACCEPT")) { Optional port = Optional.fromNullable(Ints.tryParse(messageWords[3])); - long position = Optional.fromNullable(Longs.tryParse(messageWords[4])).or(-1L); + long position = (messageWords.length > 4) ? Optional.fromNullable(Longs.tryParse(messageWords[4])).or(-1L) : -1; if (port.isPresent()) { eventBus.post(new DccAcceptReceived(this, client, messageWords[2], port.get(), position)); } else { @@ -742,6 +748,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic public void close() throws IOException { Closeables.close(outputStream, true); Closeables.close(inputStreamReader, true); + Closeables.close(inputStream, true); } }