Timeout during connect()

Timeout during connect()

Post by Mark Hea » Tue, 05 Aug 1997 04:00:00



I've written a program to test if services on other machines are running,
using socket and connect, in C, to open a connection to the service.  

I've also used select to see if the data is available within a certain
time.  

But the connect is taking too long to timeout.  

How can I change the Timeout value for a connect?

--
-- mark heath - Netspace Online Systems.  http://www.netspace.net.au/
Obnoxious Usenet Habits #78. Make it clear from your postings that you've
a profound inability to distinguish "The X Files" as fiction.
:wq

 
 
 

Timeout during connect()

Post by J Wuns » Tue, 05 Aug 1997 04:00:00



> How can I change the Timeout value for a connect?

It's the value of the sysctl variable net.inet.tcp.keepinit.  But you
don't wanna change it.

Instead, install an alarm handler, and trigger the timeout you want.
--
cheers, J"org


Never trust an operating system you don't have sources for. ;-)

 
 
 

Timeout during connect()

Post by Curt Wel » Tue, 05 Aug 1997 04:00:00



> I've written a program to test if services on other machines are running,
> using socket and connect, in C, to open a connection to the service.
> I've also used select to see if the data is available within a certain
> time.
> But the connect is taking too long to timeout.
> How can I change the Timeout value for a connect?

You set non blocking mode on the socet before doing
the connect something like this:

#ifdef O_NONBLOCK
    ret = fcntl(conp->s, F_SETFL, O_NONBLOCK);
#else
    ret = fcntl(conp->s, F_SETFL, O_NDELAY);
#endif

Then, the connect() won't hang.  It just starts the connect
process.  Something like this:

    ret = connect(conp->s, (struct sockaddr *)&sin, sizeof sin);

    if (ret < 0 && errno != EINPROGRESS) {
        (void)close(conp->s);
        perror("hit: connect");
        exit(1);
    }

From the connect(2) man page:

 [EINPROGRESS]     The socket is non-blocking and the connection cannot be
                   completed immediately.  It is possible to select(2) for
                   completion by selecting the socket for writing.

You then use select to find out when the connection is complete.  You
can set whatever timeout you want on the select, and if the select
times out before the connection completes, then you can consider it
an error and close the socket.

Curt Welch
http://CurtWelch.Com/

 
 
 

1. dialup problem - PPP timeout during connect

Hi, what exactly is the problem shown below in the entries from
/var/log/messages? Is it a problem on my end or the ISP end? I'm dialing out
to an ISP server using PAP.  The modem (USR v.90) initializes and dials
fine, but disconnects after a minute or so. Any suggestion would be great.
TIA,

Oct  3 18:50:59 galadriel chat[405]: send (ATDT7289768^M)
Oct  3 18:51:00 galadriel chat[405]: expect (CONNECT)
Oct  3 18:51:00 galadriel chat[405]: ^M
Oct  3 18:51:17 galadriel chat[405]: ATDT7289768^M^M
Oct  3 18:51:17 galadriel chat[405]: CONNECT
Oct  3 18:51:17 galadriel chat[405]:  -- got it
Oct  3 18:51:17 galadriel chat[405]: send (^M)
Oct  3 18:51:17 galadriel pppd[404]: Serial connection established.
Oct  3 18:51:18 galadriel pppd[404]: speed 56400 not supported
Oct  3 18:51:18 galadriel pppd[404]: Using interface ppp0
Oct  3 18:51:18 galadriel pppd[404]: Connect: ppp0 <--> /dev/ttyS0
Oct  3 18:51:58 galadriel pppd[404]: IPCP: timeout sending Config-Requests
Oct  3 18:51:58 galadriel pppd[404]: Connection terminated.
Oct  3 18:51:58 galadriel pppd[404]: Hangup (SIGHUP)
Oct  3 18:51:58 galadriel pppd[404]: Exit.
Oct  3 18:53:33 galadriel kernel: PPP: ppp line discipline successfully
unregistered

2. Network connection problem

3. 3c503: error during startup - timeout?

4. Custom kernel on 6500 power PC

5. Apache 1.2.4: Dumps core during timeout signal handling

6. porting socket program from UNIX to Win95

7. sendmail: stat=Deferred: 451 Nameserver timeout during parsing

8. YELLOW DOG LiNuX and KDE????

9. Help! irq timeouts during boot time

10. TCP/IP timeouts and hangups during network lags...

11. HD timeout during installation

12. Ethernet Card Timeouts during Boot

13. Network card device timeout during NetBSD install