Server death detection?
Tim McDaniel
mcdaniel at adi.com
Fri Oct 19 05:56:56 AEST 1990
I wrote:
> [My coworker, Dan Bergin]'s got a server and a client talking via
> sockets over a network, running under ULTRIX 4.0 and/or SUN OS 4.1.
> At some point, the server is killed. He would like the client to
> receive notification ASAP that this has occurred.
Well, my coworker has solved the problem. He had to dig through the
bowels (and "bowels" is an appropriate word) of the SUN manuals. Not
bad, considering that Dan is a VMS hacker! 8-)
/*
* gethostbyname ...
* getservbyname ...
* socket ...
* connect ...
*/
signal (SIGIO, routine);
if (fcntl (sock, F_SETOWN, getpid()) < 0) {
SOCKET_PERROR ("F_SETOWN");
exit (5);
}
if (fcntl (sock, F_SETFL, FASYNC) < 0) {
SOCKET_PERROR ("F_SETFL");
exit (5);
}
while (1) {pause ();}
"routine" is the handler for SIGIO signals. The first "fcntl" sets
the owner of the socket to be the current process (the client). The
second sets up asynchronous notification. When the server dies, an
EOF is put into the socket. Since that is readable (read won't
block), a SIGIO then occurs, and the client can look around to see the
problem. (SOCKET_PERROR is his own macro.)
This works under SUN OS 4.1 and ULTRIX.
--
Tim McDaniel Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Work phone: +1 313 973 1300 Home phone: +1 313 677 4386
Internet: mcdaniel at adi.com UUCP: {uunet,sharkey}!amara!mcdaniel
More information about the Comp.unix.programmer
mailing list