How to enable the TCP PSH
flag in write function to send the the message without filling the buffer?
Asked
Active
Viewed 3,248 times
3

terminal ninja
- 396
- 1
- 11

G.Balamurugan
- 31
- 1
- 6
-
What language are you programming in? You could add a tag with said language to your question, so people can find your question more easily. – ByteWelder Jun 27 '16 at 11:11
-
Thanks. I am working on C language – G.Balamurugan Jun 27 '16 at 11:39
-
check this thread out: http://stackoverflow.com/questions/855544/is-there-a-way-to-flush-a-posix-socket – Oleksandr Kravchuk Jun 27 '16 at 12:21
-
Sometimes, it is nice to use UDP. It is bare-bones, but then you get much more control (and more work to do) in your application layer protocol. But of course, this may be impractical for your current work. Here is an interesting article: https://1024monkeys.wordpress.com/2014/04/01/game-servers-udp-vs-tcp/ – Erik Alapää Jun 27 '16 at 12:29
-
Additional note is that there are system-dependent ways of checking for TCP ACK (for example, reading TCP_INFO in Linux), but that only tells you that the remote server has received the packets, not that the user application has read everything in the corresponding byte stream. – Erik Alapää Jun 27 '16 at 12:41
-
Setting the PSH flag is a waste of time. It doesn't make any difference at the receiver. – user207421 Jul 11 '16 at 23:28
1 Answers
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.

Wilmer
- 113
- 3