[comp.protocols.tcp-ip] Stdio over sockets

art@dinorah.wustl.edu (Arthur B. Smith) (06/24/89)

Hi!

    We are trying to do stream i/o (stdio.h stuff) over stream type
sockets in the internet address family (instead of the more
conventional (normal or character special) files or pipes), in Ultrix
3.0, and are having some problems.  We have not tried this under any
other operating systems.    

    We are constructing the FILE * stream by calling fdopen on the
socket descriptor.  The Ultrix documentation says that fdopen can be
applied to descriptors obtained from open, dup, creat or pipe.
Sockets are not mentioned as being either allowed or disallowed.
Fdopen returns non-NULL, so it presumably is succeeding, but
subsequent fprintf's seem to be failing.

    Does anyone know for sure if we can or can't do what we are trying
to do?  Since stream type sockets support the read, write and close
system calls, one would expect most operations to work.  Sockets DO
return errors to fstat calls, though, so any operation that insists on
checking the descriptor's status could fail.  

    Any help will be greatly appreciated.  Please respond by e-mail,
and I fill forward responses to any who request them.  I will post a
summary if the need seems to demand it.  Thanks in advance!

    	    -art smith (art@dinorah.wustl.edu    or
    	    	    	...!uunet!wucs1!dinorah!art)

chris@GYRE.UMD.EDU (Chris Torek) (06/26/89)

Sockets do not return errors from fstat calls.  The result of an
fstat is `the right thing'.

What is probably happening is that your program(s) do(es) not use
fflush.  If you write to a terminal device, C (not Unix: it says
to do it this way in the proposed C standard) stdio by default buffers
text up to the first newline.  Once you send a newline to a stdio
stream, the text (including the newline) is printed immediately.
Devices that are not terminals, however, get fully-buffered: text is
not printed until a `sufficiently large amount' accumulates, or until
the C program uses the fflush() stdio routine.

Any good C book should explain this, at least if it was written after
the first few drafts of the proposed standard were issued.

Chris