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) }
print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

In reply to How to shut down UNIX sockets? by bv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.