lkml.org 
[lkml]   [1997]   [Jan]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: setsockopt() and SO_RCVTIMEO (2.1.21)
    [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.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


    \
     
     \ /
      Last update: 2005-03-22 13:38    [W:0.020 / U:30.404 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site