Skip to content

Commit

Permalink
Remove timeout code -- clients can handle it themselves with SocketBo…
Browse files Browse the repository at this point in the history
…undEvent
  • Loading branch information
octylFractal committed Sep 15, 2016
1 parent 243d961 commit 3004066
Showing 1 changed file with 0 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.nio.NioEventLoopGroup;
Expand All @@ -52,7 +51,6 @@
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.ScheduledFuture;
import org.kitteh.irc.client.library.Client;
import org.kitteh.irc.client.library.event.client.ClientConnectionClosedEvent;
import org.kitteh.irc.client.library.event.user.DCCConnectedEvent;
import org.kitteh.irc.client.library.event.user.DCCConnectionClosedEvent;
Expand Down Expand Up @@ -313,29 +311,19 @@ static class DCCConnection extends ChannelInitializer<SocketChannel> {
private final InternalClient client;
// Only allow one connection per DCC. Weird, I know.
private boolean oneConnection;
private ScheduledFuture<?> timeoutFuture;

private DCCConnection(IRCDCCExchange ex, InternalClient client) {
this.exchange = ex;
this.client = client;
}

void setTimeoutFuture(ScheduledFuture<?> timeoutFuture) {
this.timeoutFuture = timeoutFuture;
}

@Override
public void initChannel(SocketChannel channel) throws Exception {
if (this.oneConnection) {
channel.close();
return;
}
this.oneConnection = true;
if (this.timeoutFuture.isCancelled() || this.timeoutFuture.isDone()) {
// channel is no longer available
return;
}
this.timeoutFuture.cancel(true);
this.exchange.setNettyChannel(channel);
dccConnections.computeIfAbsent(this.client, c -> new ArrayList<>()).add(channel);

Expand Down Expand Up @@ -473,12 +461,6 @@ static Runnable connectDCC(InternalClient client, IRCDCCExchange exchange) {
client.getEventManager().callEvent(new DCCFailedEvent(client, "Failed to bind to address " + future.channel().localAddress(), ft.cause()));
}
});
// Timeout connection after 5 seconds.
ScheduledFuture<?> timeout = eventLoopGroup.schedule(() -> {
future.channel().close();
client.getEventManager().callEvent(new DCCFailedEvent(client, "Timed out waiting for a reply.", null));
}, 5, TimeUnit.SECONDS);
childHandler.setTimeoutFuture(timeout);
return () -> future.channel().close();
}

Expand Down

0 comments on commit 3004066

Please sign in to comment.