in reply to My daemon will not restart

A simple solution would be to create the socket with SO_REUSEADDR. You can do it with IO::Socket::INET, but I'm not sure if EasyTCP allows you to do it. For an example of server which uses this socket option, see this node.

The problem is that when you shutdown your server the port still has a connection which is in the TIME_WAIT state. This is a way to make sure that all traffic on that connection has ceased. The TIME_WAIT timeout can vary, but it usually is at least 30 seconds.

Replies are listed 'Best First'.
Re^2: My daemon will not restart
by tirwhan (Abbot) on Feb 14, 2008 at 17:09 UTC
    A simple solution would be to create the socket with SO_REUSEADDR...but I'm not sure if EasyTCP allows you to do it.

    That was my first suspicion too, but Net::EasyTCP creates sockets with SO_REUSEADDR by default. From Net::Easy_TCP->_new_server():

    $sock = new IO::Socket::INET( LocalPort => $para{port}, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1, );

    All dogma is stupid.
Re^2: My daemon will not restart
by graq (Curate) on Feb 15, 2008 at 09:22 UTC

    I set up a socket 'manually', just after the $server undef, and before restart:

    . . $log->warning('Server has stopped - we need to restart!'); $server = undef; use IO::Socket::INET; use IO::String; my $listen = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 12345, Proto => 'tcp', ReuseAddr => 1 ); while( 1 ){ $log->warning( "listening....\n" ); sleep 5; } &restart_daemon; . .

    The client seems quite happy to connect to this newly created socket..

    I am really baffled.

    -=( Graq )=-