仅用于记录在分析netty源码的日志

源码调用关系图

netty源码-server端绑定端口流程

Netty Server示例

        EventLoopGroup boss = new NioEventLoopGroup(1);
        EventLoopGroup io = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(boss, io);
        bootstrap.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<NioSocketChannel>() {
            @Override
            protected void initChannel(NioSocketChannel ch) throws Exception {

            }
        });
        bootstrap.bind(25001).sync().addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    System.out.println("启动成功");
                } else {
                    future.cause().printStackTrace();
                }
            }
        });

代码执行到bootstrap.bind(25001)时,netty内部的绑定端口如下:

  1. AbstractBootstrap --> bind() --> doBind() --> doBind0()
  2. NioServerSocketChannel的bind方法在父类AbstractChannel类,所以channel的调用关系:AbstractChannel --> bind()
  3. DefaultChannelPipeline --> bind()
  4. AbstractChannelHandlerContext --> bind()
  5. HeadContext --> bind()
  6. AbstractChannel.AbstractUnsafe --> bind(),然后调用AbstractChannel --> doBind(),而他的实现类看下一步
  7. NioServerSocketChannel --> doBind()

相关文章:

  • 2022-12-23
  • 2021-08-26
  • 2021-09-26
  • 2018-05-08
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-16
  • 2021-03-31
  • 2022-12-23
  • 2019-07-04
  • 2021-09-07
  • 2021-07-15
  • 2022-02-09
相关资源
相似解决方案