Re: connect() question

Matti Aarnio (matti.aarnio@tele.fi)
Mon, 2 Feb 1998 20:05:57 +0000 (/etc/localtime)


> Whats the default timeout on connect()? Can a user level program alter
> this? Would it be considered useful functionality?

TCP specifications tell it is about 15 minutes.
Not all systems adhere on that, many do it faster.

Following code outlines how one can do portable timeout
error handling -- presuming one has POSIX siglongjmp()..
(things can be done with longjmp() as well, but signal
masking needs to be taken care of also..)

Things can also be done with non-blocking sockets, but
things become more complex -- but then, if one needs it,
things are already fairly complex to begin with...

sigjmp_buf jmpalarm;
sig_alarm() { siglongjmp(jmpalarm,1); }
....
signal(SIGALRM, sig_alarm);
if (sigsetjmp(jmpalarm) == 0) {
alarm(60*3); /* 3 minutes */
rc = connect(sock, ...);
} else {
/* alarm triggered, do error handling */
}

> Cheers
> Chris

/Matti Aarnio <matti.aarnio@tele.fi>