new remote code
[scpubgit/Tak.git] / lib / Tak / ConnectorService.pm
CommitLineData
77bf1d9b 1package Tak::ConnectorService;
2
3use IPC::Open2;
4use IO::All;
5use Tak::Router;
6use Tak::Client;
7use Tak::ConnectionService;
8use Moo;
9
10with 'Tak::Role::Service';
11
12has connections => (is => 'ro', default => sub { Tak::Router->new });
13
14sub handle_create {
15 my ($self) = @_;
16 my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-')
17 or die "Couldn't open2 child: $!";
18 io($kid_in)->print(io('maint/mk-fat |')->all, "__END__\n");
19 my $connection = Tak::ConnectionService->new(
20 read_fh => $kid_out, write_fh => $kid_in,
21 listening_service => Tak::Router->new
22 );
23 my $client = Tak::Client->new(service => $connection);
24 # actually, we should register with a monotonic id and
25 # stash the pid elsewhere. but meh for now.
26 my $pid = $client->do(meta => 'pid');
27 $self->connections->register('|'.$pid, $connection);
28 return ('proxy', '|'.$pid);
29}
30
31sub start_proxy_request {
32 my ($self, $req, @payload) = @_;;
33 $self->connections->start_request($req, @payload);
34}
35
36sub receive_proxy {
37 my ($self, @payload) = @_;
38 $self->connections->receive(@payload);
39}
40
411;