3 ms·
Nope, and (IMHO) you're missing the point. duping the fd's as you describe would achieve nothing, as both fds will share the same file, and hence while either
by dfawcus 3y ago
Nope, and (IMHO) you're missing the point.
duping the fd's as you describe would achieve nothing, as both fds will share the same file, and hence while either fd is open, the kernel can not detect a close.
The process-data task is on a remote machine, probably listening on a single port, and feeding its output back over the same TCP connection as its input.
Some process has then set up the series of connections, by connecting to the remote server, plumbing and doing fork/exec to run consume-data with the socket on stdin, while doing an exec of generate-data having the socket on stdout.
Now the processes being run are assumed to be general unix processes, i.e. pipeline processes ala how cat, head, grep etc operate. They generally read from input, write to output, and exit when the input is exhausted. That "exit signal" will then be fed through the pipeline as a series of "EOF" notifications, which FIN can achieve for TCP.
However because the output fd from generate-data, and the input fd to consume-data both share the same underlying socket, the mere close of the output fd from generate-data exiting will not result in a FIN being sent to process-data.
That is because the same "file" (the socket) is open by consume-data (in read/write mode), and so the kernel can not know that consume-data will not write to the socket.
If the UNIX abstraction for the sockets had the ability to split the socket across to "files", not just fds, then the issue would be removed; but it doesn't.
- charcircuit 3y ago>and hence while either fd is open, the kernel can not detect a close. Which is what the author wants. He wants the socket to close once both generate-data and consume-data are done with the socket.
- dfawcus 3y agoNo, he wants a way for the close of the FD from generate-data to process-data to trigger a TCP FIN over the connection, such that process-data sees an input EOF. However for that to work, the two FDs (generate-date to process-data, and process-data to consume-data) must not be associated with the same "open file", even though they could (with a change) represent the same TCP socket. i.e. he wants generate-data to exit, closing its output FD, and have that drive EOF all the way through to consume-data. Such that consume-data does not determine it is done until it sees EOF on its input socket. (One can observe a similar issue if one opens FIFO's in read/write mode, but since they can also be opened read-only or write-only, the issue does not arise.)