setsockopt / SO_RCVTIMEO

Erwin Rol Erwin.Rol at q-soft-engineering.com
Tue Jan 22 14:06:31 UTC 2002


Hello All,

I have a small problem with RTEMS 4.0.0. I changed my ticks from 100/sec to
1000/sec, everything is fine. But now i wanted to use setsockopt to set a recv
timeout on a socket and i ran into a problem, it returns with an error EDOM
error.

When lookign at the source i found the place where i think it goes wrong,
namely in 
..../c/src/lib/libnetworking/kern/uipc_socket.c there is tested if the seconds
value is within range.

                case SO_RCVTIMEO:
                    {
                        struct timeval *tv;
                        short val;

                        if (m == NULL || m->m_len < sizeof (*tv)) {
                                error = EINVAL;
                                goto bad;
                        }
                        tv = mtod(m, struct timeval *);
                        if (tv->tv_sec > SHRT_MAX / hz - hz) {
                                error = EDOM;
                                goto bad;
                        }
                        val = tv->tv_sec * hz + tv->tv_usec / tick;


SRT_MAX = 65535 
hz = 1000
tick = 1000

so the number of seconds may not be larger than 65535/1000 - 1000 = -934 sec
of course this works fine for hz = 100 -> 65535/100 - 100 = 555 sec
but thats still wrong, it should be (correct me if i am wrong) 
(SRT_MAX - hz) / hz   or  SRT_MAX / hz - 1 than it would like this
(65535-1000) / 1000  = 64 sec.  or (65535-100)/100 = 654 sec. 

Maybe it is already fixed in new release , but i don't have the sources of
them here so i couldn't check.

- Erwin



More information about the users mailing list