示例#1
0
        protected internal override void Start0()
        {
            if (_channel != null)
            {
                return;
            }

            _workerGroup = new NioEventLoopGroup(0, _threadFactory);

            ServerBootstrap bootstrap = (new ServerBootstrap()).group(_workerGroup).channel(typeof(NioServerSocketChannel)).option(ChannelOption.SO_REUSEADDR, true).localAddress(_listenAddress.socketAddress()).childHandler(_childInitializer.asChannelInitializer());

            if (_parentHandler != null)
            {
                bootstrap.handler(_parentHandler);
            }

            try
            {
                _channel = bootstrap.bind().syncUninterruptibly().channel();
                _debugLog.info(_serverName + ": bound to " + _listenAddress);
            }
            catch (Exception e)
            {
                //noinspection ConstantConditions netty sneaky throw
                if (e is BindException)
                {
                    string message = _serverName + ": address is already bound: " + _listenAddress;
                    _userLog.error(message);
                    _debugLog.error(message, e);
                }
                throw e;
            }
        }