简体   繁体   English

为什么TCP保持活动数据包不触发I / O事件? 是因为没有有效载荷或序列号比连接的序列号小1

[英]why TCP keep-alive packet doesn't trigger I/O event? Is it because no payload or sequence number is 1 less than sequence number of connection

I want to let my application layer notified when my server received Keep Alive Packet. 我想让我的服务器在收到“保持活动数据包”时通知应用程序层。 I am wondering what's the reason Keep Alive packet doesn't trigger I/O event. 我想知道“保持活动”数据包不触发I / O事件的原因是什么。 Is it because the TCP Keep Alive packet has no data or sequence number is 1 less than the sequence number of connection. 是因为TCP Keep Alive数据包没有数据,还是序列号比连接的序列号小1。

I did some test to let my client sent Keep Alive Packets. 我做了一些测试,让我的客户发送“保持活动数据包”。 My server use epoll but didn't get triggered. 我的服务器使用epoll,但未触发。

I am also wondering if I pad one byte to Keep Alive packet data/payload, will my application get notified/ I/O event / Epoll triggered? 我也想知道我是否填充一个字节以保持活动数据包数据/有效载荷,我的应用程序是否会收到通知/ I / O事件/ Epoll触发?

You should not be surprised by that. 您不必为此感到惊讶。 For example, you are not notified of RST packets either. 例如,您也不会收到RST数据包的通知。

Those are transport-level messaging details. 这些是传输级消息传递详细信息。 On the application level, TCP gives you stream of bytes, independent of low-level details. 在应用程序级别,TCP为您提供字节流,而与低级详细信息无关。 If you want to have application-level heartbeats, you should implement them on the application level protocols. 如果要具有应用程序级心跳,则应在应用程序级协议上实现它们。

Your latest edit seems to be stemming from some sort of confusion. 您的最新编辑似乎源于某种混乱。 You can't add data into Keep Alive packets, for two reasons: 您不能将数据添加到Keep Alive数据包中,原因有两个:

  • First, they are sent by network layer and application doesn't have control over them (beside timeouts) 首先,它们是由网络层发送的,应用程序无法控制它们(除了超时)
  • More importantly, if by some (dark) magic you manage to interfere with network layer (say, you patch your kernel :) and start putting data into them, they will stop being keep alive packets, and will become normal data packets, carrying data. 更重要的是,如果您通过某种(深色)魔术来设法干扰网络层(例如,对内核进行了修补:)并开始将数据放入其中,则它们将不再是保持活动状态的数据包,而将变为正常的数据包,从而承载数据。 Than, of course, your receiver will be notified of the data, which will become part of the message stream. 当然,不但如此,您的接收者还将收到有关数据的通知,这些数据将成为消息流的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM