Help: shutdown(..., SHUT_WR) on TCP sockets
Florian Weimer
fweimer@redhat.com
Mon Jul 8 13:19:00 GMT 2019
* Sergey Organov:
> Maybe, but honestly, I fail to see how adding 'shutdown(fd, SHUT_WR)'
> anywhere before 'close(fd)' can do things worse from the POV of data
> delivery to the other end.
>
> What I observe is that either:
>
> sleep(1);
> close(fd);
> exit(0);
>
> or:
>
> sleep(1);
> shutdown(fd, SHUT_WR);
> close(fd);
> exit(0);
>
> deliver all the data, while:
>
> shutdown(fd, SHUT_WR);
> sleep(1);
> close(fd);
> exit(0);
>
> cuts some of the data (read() returns 0 on the other end indicating
> closed socket).
Wait, you get less data with the last sequence? And you do not write to
fd after the shutdown call?
That should definitely not happen.
> Another mystery is that 'ioctl(fd, TIOCOUTQ, &v)' gives 0 in all the
> above cases when put at the beginning of the above sequences[*],
> indicating that there are no pended data, so there should be nothing to
> loose in the first place, one way or another.
Yes, I agree that data loss should not happen in these cases. There has
to be something else that triggers an RST segment, or perhaps there is a
middlebox with a broken TCP implementation.
Thanks,
Florian
More information about the Libc-help
mailing list