Re: setsockopt problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nobody has a clue on this?

Brian Brunner
brian.t.brunner@xxxxxxxxxxxxxxx
(610)796-5838

>>> brian.t.brunner@xxxxxxxxxxxxxxx 02/10/04 04:18PM >>>
what I want:
 sockets on system1 to realize the other end on system2 is dead, 
    so select() returns an exception condition on the socket to the dead system. 
    I want this to happen within about 5 seconds of yanking the network or AC cable to System2.

What I get: system1 'realizes' system2 is unplugged about 2 minutes after the fact.

What I do: setsockopts on each socket opened between system1 & 2 as follows:

int SetSocketOptions(int fd)
{
    int errval = 0;
    if (fd >= 0)
    {
	int val = 1;
	int step = 0;
	struct linger myLinger = {1,0}; // wait 0 seconds for data to drain from the OutQ before returning from close(); cause RST/ABORT on this socket.

#define MAYBEDO(a,b,c,d,e,f,g) { if ((a) == 0) {(a) |= setsockopt(c,d,e,f,g); b++;}}

	MAYBEDO(errval,step,fd,SOL_SOCKET,SO_LINGER,&myLinger,sizeof(myLinger));
	// man ip: A  TCP local socket address that has been bound is unavailable for
	// some time after closing, unless the SO_REUSEADDR flag has been set.  Care
	// should be taken when using this flag as it makes TCP less reliable.
	MAYBEDO(errval,step,fd,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val));
	val = 1;
	MAYBEDO(errval,step,fd,SOL_SOCKET,SO_KEEPALIVE,&val,sizeof(val));
	// Cause 2 second wait before first keepalive, a 2 second interval between them, and a max count of 2 before giving up on the socket.
	val = 2;
	MAYBEDO(errval,step,fd,SOL_TCP,TCP_KEEPINTVL,&val,sizeof(val));
	MAYBEDO(errval,step,fd,SOL_TCP,TCP_KEEPIDLE,&val,sizeof(val));
	MAYBEDO(errval,step,fd,SOL_TCP,TCP_KEEPCNT,&val,sizeof(val));
	// Do not delay transmission to coalesce packets (Nagle Algorithm); each should go promptly by itself.
	MAYBEDO(errval,step,fd,IPPROTO_TCP, TCP_NODELAY,&val,sizeof(val));
	if (errval)
	{
	    printf("setsockopt(%d) returned error %s step %d ", fd, strerror(errno), step);
	}
    }
    else errval = fd;    // any non-zero return will do.
    return errval;
}


Brian Brunner
brian.t.brunner@xxxxxxxxxxxxxxx 
(610)796-5838



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept
for the presence of computer viruses.

www.hubbell.com - Hubbell Incorporated
**********************************************************************


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx 
https://www.redhat.com/mailman/listinfo/shrike-list



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept
for the presence of computer viruses.

www.hubbell.com - Hubbell Incorporated
**********************************************************************


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux