Dropping stuck sockets...

From: Jeff (jfink@csugrad.cs.vt.edu)
Date: 04/25/94


A couple weeks ago, someone posted a question about users who get sockets
stuck on their system.  The response was that the only way to solve the
stuck socket problem was to reboot.  I talked to my local Unix networking
guru, and he came up with a solution.  Let me first say that this works
fine on Circle 2.2 being run on Ultrix 4.3a.  It works whether the MUD 
is shutdown or core dumps.  There is one catch.  The portion of the code
falls within an ifdef statement, so if you're running linux or SVR4, you'll
need to modify the part of the code in the ifdef statement, where everyone 
else can just substitute the else branch with the code I have below.

At any rate, here's how it goes.  Go into comm.c and look for void nonblock().
Go to the one that your system uses (if you have linux or SVR4, it's the first
one, otherwise it's the second one) and make it look like the one below.

		 Just to make sure everyone understands:

	IF YOU HAVE LINUX OR SVR4, YOU CAN NOT BLINDLY SUBSTITUTE YOUR 
		    CODE WITH THE CODE FRAGMENT BELOW.



void    nonblock(int s)
{
   struct linger ld;

   if (fcntl(s, F_SETFL, FNDELAY) == -1) {
      perror("Fatal error executing nonblock (comm.c)");
      exit(1);
   }

   /* Set linger to on with 0 second delay */
   ld.l_onoff = 1;
   ld.l_linger = 0;
   if (setsockopt(s, SOL_SOCKET, SO_LINGER, &ld, sizeof(ld)) < 0) {
      perror("setsockopt LINGER");
      exit(1);
   }

}



I'd appreciate knowing if this solves the problem that people have been
having on systems other than what I'm running (a Dec on Ultrix).  I'm not
sure how compatible this code is, or how other systems will react because
it deals with OS specific code (even though it SHOULD be compatible).

Good luck!
-Jeff



This archive was generated by hypermail 2b30 : 12/07/00 PST