when is the push flag set in tcp segment
Asked Answered
C

2

8

i asked this previous question here:

tcp two sides trying to connect simultaneously

i tried the method given in the solution and while sending while using netcat and sniffing packets with ethereal i observed that when i sent a "hello" string from one side to the other it was sent in a segment with the push flag set.

who decides to set the push flag? what are the rules for setting the push or urgent flag in a tcp segment? is it possible to do it using the sockets api?

Catanddog answered 15/2, 2010 at 5:22 Comment(0)
I
7

The PUSH flag is used by the tcp stack to basically say "i'm done for now". It's just indicating the data segment is fully transmitted by the source.

There is no way to indicate or control it in userland (your socket api), as this is just the tcp stack/implementation to do it. As the URGENT flag.

(Source: Richard Stevens - Tcp/ip illustrated vol 1, chapter 20)

Inside answered 15/2, 2010 at 8:56 Comment(1)
The above comment is wrong about there not being a way to control the sent push flag from userspace. See TCP_NODELAY and TCP_CORK socket options (man 7 tcp) and MSG_MORE flag (man 2 send).Soluk
P
6

You can set the URGENT flag using send() with the MSG_OOB flag set. As this implies, the data sent will be Out-Of-Band, meaning it will not normally be received by the calling side simply calling read(). The receiving side will get some indication of OOB data like the signal SIGURG, or the socket will become exceptional and can be checked as such using select().

Most of the time you don't want to set the URGENT flag.

Pennon answered 16/2, 2010 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.