When does a Netty ChannelFuture for a write operation become “done?”

后端 未结 1 785
眼角桃花
眼角桃花 2021-01-22 21:16

In Netty 4, when, exactly, does the ChannelFuture for a write operation (let\'s say to an NioSocketChannel) become \"done?\" Does Netty wait for an

相关标签:
1条回答
  • 2021-01-22 21:35

    Netty does not wait for ACK packets. ACK packets are an implementation detail of TCP that is mostly (entirely? yes in java, but not sure about socket api's in C) hidden to the application using a socket. If you need to know when messages are delivered you should add an acknowledge component to your application layer protocol.

    In Netty 3.x, Netty would call the success method (and notify listeners) on a ChannelFuture after the given message was written to the socket. I'm not as familiar with the Netty 4 implementation details, but from my tracing though the source I believe this is also true in Netty 4.

    ChannelOutboundBuffer.remove() @ ChannelOutboundBuffer.java:263 sets the success of the future and is called by NioSocketChannel.doWrite(ChannelOutboundBuffer) @ NioSocketChannel.java:264 after a message is done being written to the socket.

    Note that being written to the socket doesn't necessarily mean the message has been sent (partially or entirely), only that it has been written to the send buffer for the socket in the TCP layer.

    0 讨论(0)
提交回复
热议问题