Timing out of a connect(2)

Timing out of a connect(2)

Post by Mike Wal » Thu, 27 Feb 1992 05:39:20



How can I get the connect() system call to time out faster?  My applications
use internet domain SOCK_STREAM sockets on an Ethernet, and the time
outs associated with connect() are much longer then I need.  Is there a
graceful way of cutting down on the time out interval, or am I going to
have to do something like set a timer to interrupt myself out of the connect?
If I do go that route, what state is that going to leave the would-be
connection in?

Thanks in advance.

Mike

--

Mitra Imaging                          (519) 746-2900

 
 
 

Timing out of a connect(2)

Post by Kartik Subbar » Fri, 28 Feb 1992 23:17:00



>How can I get the connect() system call to time out faster?  My applications
>use internet domain SOCK_STREAM sockets on an Ethernet, and the time
>outs associated with connect() are much longer then I need.  Is there a
>graceful way of cutting down on the time out interval, or am I going to
>have to do something like set a timer to interrupt myself out of the connect?

The connect(2) man page says that you can mark the socket as non-blocking
and select() on it for writing to see when the connection has been
established. select() allows you to set a timeout.

Here's what I do:

        /* set socket to non - blocking so that we can tell quickly if the
         * host is down.
         */
        fcntl(s, F_SETFL, FNDELAY);
        if (connect(s, &sockad, sizeof(sockad)) == -1 && errno != EINPROGRESS) {
                printf("connect: %s\n", sys_errlist[errno]);
                return;
        }

        FD_ZERO(&fds); FD_SET(s, &fds);
        tv.tv_sec = 1; tv.tv_usec = 0; /* 1 second timeout */

        switch(select(maxfds, NULL, &fds, NULL, &tv)) {
        case 0: printf("not responding -- possibly down\n"); return;
        case -1: printf("select: %s\n", sys_errlist[errno]); return;
        default: break;
        }

        /* set socket back to blocking again before we read from it */
        fcntl(s, F_SETFL, 0);

        /* Do stuff with the connected socket... */

--
nfs server internet ok

 
 
 

1. RPC time outs at boot time

Recently I've just started having a problem at boot time, when my system is
starting up, I get a bunch of messages:
NFS Portmap: RPC: Port mapper failure - RPC: Timed out.

I'm currently at a loss as to what to do to fix this.
The machine that is booting is set up to mount a few filesystems over NFS,
but it has booted up fine before.  Perhaps I have a problem with my
tcpwrappers setup? (denying ALL:ALL)

Thanks in advance for any advice, help, etc...

--
John Osborne       " I love the smell of fdisk in the morning... "

2. RedHat telnet server

3. fix VIA Rhine time outs (some)

4. XDM without on console question

5. Netscape time-outs

6. Throw away your TV (Re: Soon recording TV shows will be illegal!)

7. named configuartion in a ppp setup - time outs

8. hey flattie:

9. Socket to SMTP server - periodic time outs

10. SCSI Time Outs? Please Help.

11. Jserv time outs

12. * rwall and shutdown: rpc time-outs *

13. Scsi host time outs -- help