Created
November 23, 2009 22:43
-
-
Save leedo/241448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use IO::Socket::INET; | |
use AnyEvent::Socket; | |
use AnyEvent::Handle; | |
use FindBin; | |
use lib "$FindBin::Bin/../lib"; | |
use App::Alice; | |
my $confdir = "/home/leedo/alices"; | |
mkdir $confdir unless -d $confdir; | |
my $c = AE::cv; | |
my $guard = tcp_server undef, 8888, sub { | |
my ($fh, $host, $port) = @_; | |
my $handle; $handle = AnyEvent::Handle->new( | |
fh => $fh, | |
on_error => sub { | |
my ($handle, $fatal, $msg) = @_; | |
warn "got error $msg\n"; | |
$handle->destroy; | |
}, | |
); | |
$sock = IO::Socket::INET->new(LocalPort => 0, Listen =>1); | |
my $port = $sock->sockport; | |
$sock->shutdown(2); | |
$sock = undef; | |
App::Alice->new( | |
port => $port, | |
path => "$confdir/$port", | |
standalone => 0, | |
)->run; | |
$handle->push_write($port); | |
$handle->on_drain(sub {undef $handle}); | |
}; | |
$c->recv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment