bv has asked for the wisdom of the Perl Monks concerning the following question:
Hey all. I'm trying to code up a simple within-the-machine chat server using IO::Socket::UNIX. My problem (I wish there were only one!) is this: When I Ctrl-C the server, the FIFOs related to the sockets are not cleaned up, so running it again gives me
Problem: Address already in use at chatserv.pl line 8;
I am trapping SIGINT and calling IO::Socket::shutdown(3) on the sockets. Do I need to actually unlink the FIFOs, too? Here's an example code:
#!/usr/bin/perl use strict; use warnings; use threads; use IO::Socket::UNIX; my $serv = IO::Socket::UNIX0>new( Type => SOCK_STREAM, Local => '/var/tmp/chat/serv', Listen => 1, ) or die "Problem: $!"; my $msgthr = threads->create('messenger'); $SIG{INT} = sub { $serv->shutdown(3); #this line gives a "uninitialized value" error: print STDERR "Serv status:", $serv->connected(),"\n"; #similar handler in &messenger tries to shut down #another socket, this one of type SOCK_DGRAM $msgthread->kill('TERM')->detach(); exit(0) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to shut down UNIX sockets?
by ig (Vicar) on Sep 01, 2009 at 19:31 UTC | |
by bv (Friar) on Sep 01, 2009 at 20:30 UTC | |
by ig (Vicar) on Sep 01, 2009 at 20:48 UTC | |
|
Re: How to shut down UNIX sockets?
by hnd (Scribe) on Sep 01, 2009 at 19:06 UTC | |
by bv (Friar) on Sep 01, 2009 at 19:19 UTC | |
by hnd (Scribe) on Sep 01, 2009 at 19:44 UTC |