[comp.unix.wizards] AF_INET Stream Sockets & Server/Client Models

jpdres14@usl-pc.UUCP (Collett Donald L) (01/11/88)

Thanks to everyone who sent me mail in regards to my full-duplex question.  I
have since then made much progress running full-duplex sockets using select,
FD_ZERO, FD_SET, FD_ISSET, and FD_SETSIZE.

I now have a new question.  I am developing a server/client model.  Please note
that the server is NOT a child process of the client NOR is the client a child
process of the server.  Take the situation were the server and the client have
been connected and communicating on the AF_INET stream socket.  The user running
the client program suddenly types control-C or the client program dies for some
unknown reason.  How does the server detect that the client is dead?

Don Collett
jpdres14@usl-pc.USL
ut-sally!usl-pc!jpdres14

fkittred@bbn.COM (Fletcher Kittredge) (01/12/88)

[ how can you tell if one end of a socket connection has abnormally
  terminated?]

    On Ultrix (BSD 4.[23] type) systems, if a process which has an
UNIX domain socket open dies (your client), the process on the other
end of the socket (your server) will receive the signal EPIPE when the
server attempts to write to the socket.

    Using the SO_KEEPALIVE socket option causes messages to be
periodically transmitted on a socket to test the state of the socket.
If you set your socket options correctly, when client doesn't respond
to the keepalive messages, then the EPIPE signal should be generated
for the server.  You can catch this signal and do whatever.

fletcher

matt@oddjob.UChicago.EDU (Java Man) (01/15/88)

In article <573@usl-pc.UUCP> jpdres14@usl-pc.UUCP (Collett Donald L) writes:

) ...  The user running the
) client program suddenly types control-C or the client program dies
) for some unknown reason.  How does the server detect that the
) client is dead?

When the client exits the kernel closes all its fd's.  Since you say
you are now conversant with select(), you can discover a dead client
as follows.  When select() indicates the fd is readable but read()
returns 0 bytes, the socket has been closed.
________________________________________________________
Matt	     University		matt@oddjob.uchicago.edu
Crawford     of Chicago     {astrovax,ihnp4}!oddjob!matt