lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


--- Dave Dodge <dododge@dododge.net> wrote:
Of course just as with sockets, any application 
making use of this bidirectionality will need
to be redesigned if you want to run it on a system
with the more traditional unidirectional pipes.

I have a question. If I dup2() the stdin/stdout(as in
inetd/tcpserver) using one end of socketpair() and
execute the child, would that make it work even the
child is expecting pipe like fd as its stdin/stdout ?

Using dup2 would give you two read/write file descriptors. If you close one nothing happens, because the Unix kernel waits until the last once is closed before doing anything. Closing stdout/fd 1 in a inetd client will not magically do a 'shutdown' on the sending side of a TCP connection. Bernstein's problem still exists.


Another related issue, must I use shutdown() for
socket or just close(fd) would do the same thing ?


A call to 'shutdown' signals that you are done sending or receiving information. It's mostly useful if you want to effectively send an end-of-file but you want to continue reading the reply. If you want to stop reading and writing altogether just use 'close', it effectively does a shutdown in both directions and remove the socket handle.


--
Gé Weijers