Ensure channel is set before returning from bind().

This commit is contained in:
Steven Smith 2015-08-21 20:08:13 -07:00
parent ce140f43d6
commit 9c1ac6aa9b

View file

@ -87,24 +87,29 @@ public class TcpConnectionListener implements ConnectionListener {
server.addSession(session); server.addSession(session);
} }
}).group(this.group).localAddress(this.host, this.port).bind().addListener(new ChannelFutureListener() { }).group(this.group).localAddress(this.host, this.port).bind();
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if(channelFuture.isSuccess()) {
channel = channelFuture.channel();
callback.run();
} else if(channelFuture.cause() != null && !wait) {
System.err.println("[ERROR] Failed to asynchronously bind connection listener.");
channelFuture.cause().printStackTrace();
}
}
});
if(wait) { if(wait) {
try { try {
future.sync(); future.sync();
} catch(InterruptedException e) { } catch(InterruptedException e) {
} }
channel = future.channel();
callback.run();
} else {
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if(channelFuture.isSuccess()) {
channel = channelFuture.channel();
callback.run();
} else if(channelFuture.cause() != null && !wait) {
System.err.println("[ERROR] Failed to asynchronously bind connection listener.");
channelFuture.cause().printStackTrace();
}
}
});
} }
} }