From 49a22f188fcb0071cc532f26b540a23f8950cfd4 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 28 Apr 2013 09:42:38 +1000 Subject: [PATCH] Alert when we cannot bind --- .../main/java/net/md_5/bungee/BungeeCord.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 0a5589e3..af4aab26 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -9,6 +9,8 @@ import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelException; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.MultithreadEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; @@ -218,18 +220,29 @@ public class BungeeCord extends ProxyServer public void startListeners() { - for ( ListenerInfo info : config.getListeners() ) + for ( final ListenerInfo info : config.getListeners() ) { - Channel server = new ServerBootstrap() + new ServerBootstrap() .channel( NioServerSocketChannel.class ) .childAttr( PipelineUtils.LISTENER, info ) .childHandler( PipelineUtils.SERVER_CHILD ) .group( eventLoops ) .localAddress( info.getHost() ) - .bind().channel(); - listeners.add( server ); - - getLogger().info( "Listening on " + info.getHost() ); + .bind().addListener( new ChannelFutureListener() + { + @Override + public void operationComplete(ChannelFuture future) throws Exception + { + if ( future.isSuccess() ) + { + listeners.add( future.channel() ); + getLogger().info( "Listening on " + info.getHost() ); + } else + { + getLogger().log( Level.WARNING, "Could not bind to host " + info.getHost(), future.cause() ); + } + } + } ); } }