Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - TCP_KEEPALIVE: (5 Items)
   
TCP_KEEPALIVE  
I have been trying to change the TCP_KEEPALIVE time but it hasn’t effective, keepalive still occurs at 2 hours.  

I create my socket (socket() call).  Then set the socket options (the two concerning keep alive are)
1) SO_KEEPALIVE (level=SOL_SOCKET) = 1  (if I then do a get it returns 8).
2) TCP_KEEPALIVE (level=IPPROTO_TCP)= 10 or 300  (I get back what I set)
I then proceed to call bind(), listen() and accept().  When the connection comes in, data comes through correctly.  If I
 let the connection sit open the keepalive packets go out at 2 hours.

I read under getsockopt() that TCP_KEEPALIVE takes a "struct timeval" but I can’t find the structure defined in any of 
your header files.  sys\select.h lists it, but doesn’t define it.  Also the getsockopt() returns that the size is 4 
bytes which leads me to believe it is expecting a long, not the "struct timeval".

I am currently using io-net.  I will be moving io-pkt in the future.  

Am I doing something wrong or is KEEPALIVE time not variable?  Is it going to be supported in io-pkt?
RE: TCP_KEEPALIVE  
Hi Jared:
	Someone else may jump in here with more info, but my first guess
is that the KEEPALIVE socket option is for enabling / disabling only the
timers only. I think that the keep alive timers are global and therefore
are set as stack variables rather than socket level variables.

If you do 

/sbin/sysctl -a

You'll see keepidle, keepintvl and keepcnt values.

You can change the defaults with (e.g.)

/sbin/sysctl -w net.inet.tcp.keepidle=15000

	Robert.

-----Original Message-----
From: Jared Roundy [mailto:jroundy@zebra.com] 
Sent: Friday, June 06, 2008 4:10 PM
To: technology-networking
Subject: TCP_KEEPALIVE

I have been trying to change the TCP_KEEPALIVE time but it hasn't
effective, keepalive still occurs at 2 hours.  

I create my socket (socket() call).  Then set the socket options (the
two concerning keep alive are)
1) SO_KEEPALIVE (level=SOL_SOCKET) = 1  (if I then do a get it returns
8).
2) TCP_KEEPALIVE (level=IPPROTO_TCP)= 10 or 300  (I get back what I set)
I then proceed to call bind(), listen() and accept().  When the
connection comes in, data comes through correctly.  If I let the
connection sit open the keepalive packets go out at 2 hours.

I read under getsockopt() that TCP_KEEPALIVE takes a "struct timeval"
but I can't find the structure defined in any of your header files.
sys\select.h lists it, but doesn't define it.  Also the getsockopt()
returns that the size is 4 bytes which leads me to believe it is
expecting a long, not the "struct timeval".

I am currently using io-net.  I will be moving io-pkt in the future.  

Am I doing something wrong or is KEEPALIVE time not variable?  Is it
going to be supported in io-pkt?


_______________________________________________
Technology
http://community.qnx.com/sf/go/post8852
RE: TCP_KEEPALIVE  
You should be able to adjust the timers per socket with TCP_KEEPALIVE,
struct timeval being defined in sys/time.h.  

One thing that you may have to watch for is that not all socket options
are inherited by the accept()ing socket. You may have to set the option
against the socket returned by accept() rather than the listening
socket. 

Dave

> -----Original Message-----
> From: Robert Craig [mailto:rcraig@qnx.com]
> Sent: Friday, June 06, 2008 4:33 PM
> To: technology-networking
> Subject: RE: TCP_KEEPALIVE
> 
> Hi Jared:
> 	Someone else may jump in here with more info, but my first guess
> is that the KEEPALIVE socket option is for enabling / disabling only
the
> timers only. I think that the keep alive timers are global and
therefore
> are set as stack variables rather than socket level variables.
> 
> If you do
> 
> /sbin/sysctl -a
> 
> You'll see keepidle, keepintvl and keepcnt values.
> 
> You can change the defaults with (e.g.)
> 
> /sbin/sysctl -w net.inet.tcp.keepidle=15000
> 
> 	Robert.
> 
> -----Original Message-----
> From: Jared Roundy [mailto:jroundy@zebra.com]
> Sent: Friday, June 06, 2008 4:10 PM
> To: technology-networking
> Subject: TCP_KEEPALIVE
> 
> I have been trying to change the TCP_KEEPALIVE time but it hasn't
> effective, keepalive still occurs at 2 hours.
> 
> I create my socket (socket() call).  Then set the socket options (the
> two concerning keep alive are)
> 1) SO_KEEPALIVE (level=SOL_SOCKET) = 1  (if I then do a get it returns
> 8).
> 2) TCP_KEEPALIVE (level=IPPROTO_TCP)= 10 or 300  (I get back what I
set)
> I then proceed to call bind(), listen() and accept().  When the
> connection comes in, data comes through correctly.  If I let the
> connection sit open the keepalive packets go out at 2 hours.
> 
> I read under getsockopt() that TCP_KEEPALIVE takes a "struct timeval"
> but I can't find the structure defined in any of your header files.
> sys\select.h lists it, but doesn't define it.  Also the getsockopt()
> returns that the size is 4 bytes which leads me to believe it is
> expecting a long, not the "struct timeval".
> 
> I am currently using io-net.  I will be moving io-pkt in the future.
> 
> Am I doing something wrong or is KEEPALIVE time not variable?  Is it
> going to be supported in io-pkt?
> 
> 
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post8852
> 
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post8854
Re: RE: TCP_KEEPALIVE  
> You should be able to adjust the timers per socket with TCP_KEEPALIVE,
> struct timeval being defined in sys/time.h.  
> 
> One thing that you may have to watch for is that not all socket options
> are inherited by the accept()ing socket. You may have to set the option
> against the socket returned by accept() rather than the listening
> socket. 
> 
> Dave


Dave is correct. TCP_KEEPALIVE is per socket, so you have to set it on the socket returned by accept(), not the listen 
one.

Also, TCP_KEEPALIVE only changes when should a KEEPALIVE packet send out. But it still take the standard TCP timeout 
time to decided drop the connection. Ie, if you set TCP_KEEP_ALIVE to, say 10 seconds; then after 10 seconds the first 
KEEPALIVE packet would send out, if no reply, it will resend ..., and (if I remember correct) it takes another 9.5 
minutes to decided the other side is not there, and then the connection dropped.
Re: RE: TCP_KEEPALIVE  
The /sbin/sysctl command works to change the keepalive packet timing.  keeptidle is 2 times when the first keep alive 
packet is sent.  keepintvl is 2 times the wait between keep alive packets.  keepcnt is how many packets to send and wait
 on before closing the connection. 

The getsockopt() must not use the "struct timeval" because it only returns 4 bytes.  You are correct that I need to set 
the value for the new socket created by accept().

Thanks for the help.