KEEPALIVE does not work

Gary Mills mills at ccu.umanitoba.ca
Mon Feb 11 03:29:37 AEST 1991


I attempted to modify a network daemon to enable `keepalive' on a TCP socket.
A code fragment is included below, with my addition inside an ifdef.  I removed
the error returns to shorten this article.  The code appears to work, but when
I watch the packets with etherfind on another machine, I can't see the
keepalive packets.  Should they be visible?  Did I miss something?  Does SunOS
4.1 not suport keepalive?  In case anyone wonders, the non-blocking i/o is
disabled later in the code, after a select().  The TCP read is always
interrupted by an alarm.  Could this interfere with keepalive?  I would like to
use keepalive so my daemon can detect when the remote host breaks its TCP
connection.  On an idle connection, my daemon spends most of its time in the
TCP read.


sc = socket(AF_INET, SOCK_STREAM, 0);
if (sc < 0) {
}
#ifdef UOFMCC
if (setsockopt(sc, SOL_SOCKET, SO_KEEPALIVE, (char *)(n=1, &n), sizeof(n)) < 0) {
}
#endif
if (ioctl(sc, FIONBIO, (char *)(n=1, &n)) < 0) {
}

if (connect(sc, (struct sockaddr *)&toaddr, sizeof(toaddr)) < 0) {
	if (errno != EINPROGRESS && errno != EWOULDBLOCK) {
	}
}
-- 
-Gary Mills-         -Networking Group-          -U of M Computer Services-



More information about the Alt.sys.sun mailing list