News for hackers. Stuff that matters.
Re:Two File Descriptors for Sockets by pif on Monday January 22, 2024 @05:03AM (#39087953)
Maybe I'm not getting it completely...

In the first example, he is using two pipes; in the second example, he is using one socket. And he complains that that they don't work the same!?!

Re:Two File Descriptors for Sockets by greybrunix on Monday January 22, 2024 @05:11AM (#39087990)
I think the point is that a socket is doing both reading and writing using the same file descriptor, which is counterintuitive.
Re:Two File Descriptors for Sockets by Veserv on Monday January 22, 2024 @07:56AM (#39088987)
Which is a problem of their own making. If they use two sockets, which would be needed if all three programs were on different machines, then it would work exactly the same as the pipe example.

The problem is that they saw TCP sockets are two-way and then thought to optimize the TCP connection/state overhead by using it for double-duty without applying appropriate abstractions to transparently use a two-way channel as two one-way channels.

Re:Two File Descriptors for Sockets by Gabrys1 on Monday January 22, 2024 @10:28AM (#39090457)
Some early protocols used two sockets for (maybe?) roughly this reason
Re:Two File Descriptors for Sockets by dfawcus on Monday January 22, 2024 @11:02AM (#39090917)
Sort of - NCP (RFC 33) had two simplex sockets.

Even being receive, odd transmit. That then led to various higher level protocols using pairs of ports. Once TCP took over, that was relaxed.

Re:Two File Descriptors for Sockets by adontz on Monday January 22, 2024 @10:44AM (#39090657)
If you mean FTP, then no. One socket is for commands, another is for data. Both bidirectional.
Re:Two File Descriptors for Sockets by dfawcus on Monday January 22, 2024 @12:21PM (#39092190)
Compare with what existed when NCP (RFC 33) was in use.

An early FTP protocol (452, 454, 542) originally used a server listen port of 3 (and hence a server "return port" of 2*), but 542 allowed temporary use of port 21 as the protocol was changed. A different pair of ports (even or odd depending upon TX or RX end) were used for the data channel, and the port picked was related to the Telnet protocol port in use.

RFC 640 then seems to have fixed the use of port 21 instead of 3. Then when TCP came in to use RFC 765 seems to have simplified things somewhat, sticking to port 21.

Also see RFC 165 for the/a Telnet Initial Connection Protocol showing the use of the two even/odd ports for forming a bidirectional connection.

* Or 4, but I believe the return channel was one port below, not above.

Re:Two File Descriptors for Sockets by adontz on Monday January 22, 2024 @02:18PM (#39094035)
I believe that's a different story explained here https://news.ycombinator.com/item?id=14178993
Re:Two File Descriptors for Sockets by rnmmrnm on Monday January 22, 2024 @05:53AM (#39088167)
and that to half-close a socket you need to use some unintuitive syscall.
Re:Two File Descriptors for Sockets by pif on Monday January 22, 2024 @10:18AM (#39090347)
Use two pipes and you won't need to half-close any socket.
Re:Two File Descriptors for Sockets by cryptonector on Monday January 22, 2024 @01:48PM (#39093575)
Setting up two sockets would be even more work.

The best mitigation is to not close `stdin` when you get EOF on it -- just stop reading from `stdin`.