如何在TCP / IP堆栈中启用tcp psh标志?

时间:2016-06-27 11:06:38

标签: c linux tcp tcp-ip

如何在write函数中启用TCP PSH标志来发送消息而不填充缓冲区?

1 个答案:

答案 0 :(得分:0)

Are you not seeing your packets going out without the PSH flag set now already? Some experimentation here showed that the following packet in tcpdump:

00:00:47.633884 IP 90.155.34.205.52092 > 216.58.222.100.80: Flags [P.], seq 1:16, ack 1, win 29, options [nop,nop,TS val 35956508 ecr 2650150746], length 15: HTTP: GET / HTTP/1.0
E..CD.@.@...Z."..:.d.|.P......QM...........
.$.....ZGET / HTTP/1.0

went out using a very simple boring write() - from strace'ing netcat:

socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_REUSEPORT, [1], 4) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("216.58.222.100")}, 16) = 0
write(3, "GET / HTTP/1.0\n", 15)        = 15

It looks to me like the PSH flag is only unset on if for example I transmit more data than fits in a single segment, in which case only the last segment will have PSH, indicating there's more data coming up for now.