Article View: comp.unix.programmer
Article #1064Re: Server death detection?
From: Tim McDaniel
Date: Thu, 18 Oct 1990 19:56
Date: Thu, 18 Oct 1990 19:56
39 lines
2113 bytes
2113 bytes
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@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel
Technical Details
Message-ID:
<MCDANIEL.90Oct18155656@dolphin.adi.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!dptg!ulysses!andante!mit-eddie!mintaka!olivea!samsung!umich!sharkey!amara!mcdanielReferences:
<MCDANIEL.90Oct18111427@dolphin.adi.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!dptg!ulysses!andante!mit-eddie!mintaka!olivea!samsung!umich!sharkey!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.unix.programmer Subject: Re: Server death detection? Message-ID: <MCDANIEL.90Oct18155656@dolphin.adi.com> Date: 18 Oct 90 19:56:56 GMT References: <MCDANIEL.90Oct18111427@dolphin.adi.com> Sender: news@adi.COM Organization: Applied Dynamics International, Inc.; Ann Arbor, Michigan, USA Lines: 39 In-reply-to: mcdaniel@adi.com's message of 18 Oct 90 15:14:27 GMT