Is there a way to flush a POSIX socket?

What about setting TCP_NODELAY and than reseting it back?
Probably it could be done just before sending important data, or when we are done with sending a message.

send(sock, "notimportant", ...);
send(sock, "notimportant", ...);
send(sock, "notimportant", ...);
int flag = 1; 
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
send(sock, "important data or end of the current message", ...);
flag = 0; 
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));

As linux man pages says

TCP_NODELAY … setting this option forces an explicit flush of pending output …

So probably it would be better to set it after the message, but am not sure how it works on other systems

Leave a Comment