记录一下ByteBuffer调用路径

在某个地方_endpoint.fill(buffer);

调用_channel.read(bbuf);

这里看一下SocketChannelImpl.read方法

然后调用IOUtil.read(fd, bytebuffer, -1L, nd, readLock);

 

if(bytebuffer instanceof DirectBuffer)
            return readIntoNativeBuffer(filedescriptor, bytebuffer, l, nativedispatcher, obj);
        bytebuffer1 = null;
        int j;
        bytebuffer1 = Util.getTemporaryDirectBuffer(bytebuffer.remaining());
        int i = readIntoNativeBuffer(filedescriptor, bytebuffer1, l, nativedispatcher, obj);
 bytebuffer1.flip();
        if(i > 0)
            bytebuffer.put(bytebuffer1);
 

如果是使用了DirectBuffer,那么直接从网卡(socket)读取数据放入buffer里

否则生成一个临时的DirectBuffer,然后读取数据,再后做两个buffer的复制工作

 

你可能感兴趣的:(ByteBuffer)