1 package Object::Remote::ConnectionServer;
3 use Scalar::Util qw(blessed weaken);
4 use Module::Runtime qw(use_module);
13 return $_[0] if blessed($_[0]);
15 IO::Socket::UNIX->new(
18 ) or die "Couldn't liten to $_[0]: $!";
23 Object::Remote->current_loop
26 on_read_ready => sub { $self->_listen_ready($fh) }
31 has connection_args => (
32 is => 'ro', default => sub { [] }
35 has connection_callback => (
36 is => 'ro', default => sub { sub { shift } }
40 Object::Remote->current_loop->want_run;
44 Object::Remote->current_loop->run_while_wanted;
49 my $new = $fh->accept or die "Couldn't accept: $!";
51 my $f = CPS::Future->new;
52 my $c = use_module('Object::Remote::Connection')->new(
53 receive_from_fh => $new,
55 on_close => $f, # and so will die $c
56 @{$self->connection_args}
57 )->${\$self->connection_callback};
58 $f->on_ready(sub { undef($c) });
59 $c->ready_future->done;
60 #TODO see if this runs on the controller or the remote node
61 #if this runs on the controller a poorly behaved remote node
62 #could cause the print() to block but it's a very low probability
63 print $new "Shere\n" or die "Couldn't send to new socket: $!";
70 Object::Remote->current_loop
72 handle => $self->listen_on,
75 if ($self->listen_on->can('hostpath')) {
76 unlink($self->listen_on->hostpath);
78 Object::Remote->current_loop->want_stop;