in reply to Listening without forking
Check out the Event module. I've had pretty good luck using it for this type of thing.
# untested, almost verbatum from working code. use Event; use IO::Socket; my @peers; my $sock = IO::Socket::INET->new(Listen=>5,LocalPort=>8001,Reuse=>1) or die "[Fatal] no getum socket!\n"; Event->io( fd=>$sock; cb=>sub { my $e = shift; my $h = $e->w->fd; my $peer = $h->accept; push @peers, $peer; $peer->autoflush; Event->io( # todo: data => '<peername>' or such to id peers. fd=>$peer, cb=>sub { my $e=shift; my $h=$e->w->fd; # todo: my $name=$e->w->data; my $line = <$h>; foreach (@peers) { $_->print "$line" } # from $name... if ($line =~ /^quit/i or eof($h)) { $e->w->cancel(); # todo: remove self from @peers } } ); } ); Event::loop();
There's much more in the module, io (r/w/e), signal, timer, idle, var (r/w) handlers...
|
|---|