On Wed, Nov 14, 2001 at 12:33:48PM -0600, Michael Barton wrote:
> I had the same problem..the MUD seems to not always receive EOF when the
> player is disconnected while still being handled by nanny.  I never
> really fixed it, just put a timer on my descriptors to disconnect them
> after 20 minutes or so idle...

Well, it won't get an EOF.

The way a 'normal' TCP socket works, the stack won't notice that the
other end is there until it tries to write to it and gets either a
timeout or a reject.

Because people sitting at the "What is your name?" prompt don't get
anything sent to them until they send their name, the stack, and
therefore the MUD won't notice the machine is gone.

The way to solve this is to use the SO_KEEPALIVE parameter.  This will
tell the stack to periodically send keep-alive packets, even if there is
no real data to send.  If THOSE fail, it will eventually close the
socket.

The total code to do this:

    if ( setsockopt( fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &x,
                                                   sizeof(x) ) < 0 )
    {
        perror( "Init_socket: SO_KEEPALIVE" );
        close(fd);
        exit( 1 );
    }

This gets buried in comm.c right below the LINGER stuff.

Let the stack do your work for you.


Reply via email to