Re: setsockopt() and SO_RCVTIMEO (2.1.21)

Richard B. Johnson (root@analogic.com)
Mon, 20 Jan 1997 17:32:44 -0500 (EST)


[SNIPPED]
>
> SO_RCVTIMEO is read only. See POSIX 1003.1g draft 6.4.
>
> Does anyone know a way around this? Could I perhaps set the timeout at
> the TCP layer instead? Should I expect this option to be supported in the
> kernel anytime soon?

I have excellent luck keeping the socket blocking but using select() with
a timeout. I have also used an alarm to get out of a blocking call. Note
you do NOT have to do a longjump from the routine set by signal(), just
a dummy routine, after the timeout, the blocking call will return with
the errno set to EINTER.

void dummy (int unused)
{
/* This happens and returns immediately */
}
signal(SIGALRM, dummy);
alarm(SECONDS);
status = recv(fd, .....);
if(status < 0) ... There was an alarm timeout....

An advantage is that it is "nice" at the kernel level. Your task will
sleep until there is either ANY data available or the alarm-clock went
off.

If you are doing terminal I/O, you can use setitimer() to get microsecond
resolution instead of alarm() which gives you only seconds. 1 millisecond
is a good timeout for terminals.

Cheers,
Dick Johnson
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard B. Johnson
Project Engineer
Analogic Corporation
Voice : (508) 977-3000 ext. 3754
Fax : (508) 532-6097
Modem : (508) 977-6870
Ftp : ftp@boneserver.analogic.com
Email : rjohnson@analogic.com, johnson@analogic.com
Penguin : Linux version 2.1.21 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-