[comp.protocols.tcp-ip] connect

hughes@silver.bacs.indiana.edu (larry hughes) (08/17/89)

Does anyone know how to modify the default time that it
takes for a connect(2) to time out?  I've tried
setsockopt(2) without success (I think that's for
reads and writes, not connect).  The default time of
1:15 is too long for my application.

I've even resorted to issuing a signal(3) for SIGALRM,
which causes the connect to fail with errno EINTR,
but it only works the first time.  Does anyone know
why?

Thanks for any information...

/=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\
|| Larry J. Hughes, Senior Programmer ||  hughes@silver.bacs.indiana.edu   ||
||        Indiana University          ||  hughes@iujade.bitnet             ||
||   University Computing Services    ||                                   ||
||    750 N. State Road 46 Bypass     ||  "The person who knows            ||
||      Bloomington, IN  47405        ||     everything has a lot          ||
||         (812) 855-9255             ||       to learn."                  ||
\=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/

hwajin@wrs.wrs.com (Hwajin Bae) (08/18/89)

In article <24692@iuvax.cs.indiana.edu> hughes@silver.bacs.indiana.edu (larry hughes) writes:
>Does anyone know how to modify the default time that it
>takes for a connect(2) to time out?  I've tried
>setsockopt(2) without success (I think that's for
>reads and writes, not connect).  The default time of
>1:15 is too long for my application.

When connect() is requested, TCP protocol implementation in BSD 4.3-Tahoe 
will send a SYN packet and start a keep-alive timer.  Initially, when the
remote machine you're trying to connection to doesn't respond within
75 seconds (TCPTV_KEEP_INIT) with an ACK/SYN (initial phase of the TCP 
three-way handshake connection set-up protocol), the keep-alive timer will 
start sending a keep-alive packet (<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK)>)
every 75 seconds (TCPTV_KEEPINTVL) until it receives a packet from the
other side or upto 8 times (TCPTV_KEEPCNT).   So, 8 * 75 => 600 == 10 minutes
in 4.3 BSD.  The constants in parentheses are defined in netinet/tcp_timer.h.
You can change the global variables "tcp_keepintvl" to change the
kernel's idea of TCPTV_KEEPINTVL using adb on BSD Unix.  As in,

% adb -k -w /vmunix /dev/mem
  tcp_keepintvl?W 60

Note also that these numbers tend to vary in different implementations as
well as in various releases of BSD Unix code itself.  Pre-4.3-tahoe releases
of the networking code only had TCPTV_KEEP (45 sec) and 
TCPTV_MAXIDLE (8 * 45 sec).

-- 
Hwajin Bae
Wind River Systems
1350 Ocean Ave
Emeryville, CA 94608

hwajin@wrs.wrs.com (Hwajin Bae) (08/18/89)

Of course, the 10 minute keep-alive timeout scenario is only valid
if you don't get anything from the remote system after sending the
initial SYN packet.  If you get something back from the remote system
that cancels the keep-alive timeout, TCP will get into a bit more
complicated retransmission stage -- and subsequently will take
longer for connect() to actually time out.  TCP will keep on retransmitting
the SYN packet until it receives ACK/SYN for it.  TCP retransmission back-off
is based on the binary exponential algorithm 
	(1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64)
and the retransmission time will vary from 1 to 64 seconds and happend
upto 12 times.

-- 
Hwajin Bae
Wind River Systems
1350 Ocean Ave
Emeryville, CA 94608