Operating System - HP-UX
1827814 Members
2434 Online
109969 Solutions
New Discussion

Using TCP_KEEPALIVE option in setsockopt to detect cable break

 
Cláudia
New Member

Using TCP_KEEPALIVE option in setsockopt to detect cable break

I would like to enable tcp keepalive packets for a particular socket in a C server application hosted on HPUX 11.00. I'm trying to use the TCP_KEEPALIVE option:

int fd, ret, len, optval=1;
fd = socket(AF_INET, SOCK_STREAM, 0);
len = sizeof(optval);
// It's necessary set SO_KEEPALIVE to use TCP_KEEPALIVE
ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, optval, &len);

struct t_kpalive kp_opts;
len = sizeof(struct t_kpalive);
kp_opts.kp_onoff = 1;
kp_opts.kp_timeout = 200;
ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &kp_opts, len);

struct t_kpalive kp_optget;
len = sizeof(struct t_kpalive);
ret = getsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &kp_optget, &len);

printf("onoff=%d, timeout=%d \n", kp_optget.kp_onoff, kp_optget.kp_timeout);


The result of the printf is:
"onoff=0, timeout=0"

This means that I didn't change de timeout, right? Has anyone any ideas how to resolve the problem?

Thanks
2 REPLIES 2
donne007
Regular Advisor

Re: Using TCP_KEEPALIVE option in setsockopt to detect cable break

If the abort interval is set to a small value and the RTT estimate is a large value, then that will lead to fewer retransmissions before the connection is aborted. The application writer must understand the ramifications before they attempt to modify the values of these options. The values of these options can also be retrieved using getsockopt.


The total elapsed time is a function of the following parameters:

tcp_keepalive_interval
tcp_ip_abort_interval
Estimated round trip time

The number of retransmissions before the connection is aborted is a
function of the following parameters:

tcp_ip_abort_interval
estimated round trip time



I'm Not sure if it's possible for an application to precisely estimate or control
the total time before a connection is aborted or the number of retransmissions which are sent before the connection is aborted. These things are dependent on factors (tcp->tcp_rto) over which the application does not and should not have control.

Applications may use an application-level keepalive mechanism.This mechanism will allow the application to have precise control over the amount of time it will wait before giving up on a connection.

Hope this Helps..

Cheers
Asif
Steve Steel
Honored Contributor

Re: Using TCP_KEEPALIVE option in setsockopt to detect cable break

Hi


look at

man ndd

and

http://www.sybase.com/detail?id=611

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)