Commit | Line | Data |
77bf1d9b |
1 | package Tak::ConnectorService; |
2 | |
3 | use IPC::Open2; |
4 | use IO::All; |
5 | use Tak::Router; |
6 | use Tak::Client; |
7 | use Tak::ConnectionService; |
8 | use Moo; |
9 | |
10 | with 'Tak::Role::Service'; |
11 | |
12 | has connections => (is => 'ro', default => sub { Tak::Router->new }); |
13 | |
14 | sub 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 | |
31 | sub start_proxy_request { |
32 | my ($self, $req, @payload) = @_;; |
33 | $self->connections->start_request($req, @payload); |
34 | } |
35 | |
36 | sub receive_proxy { |
37 | my ($self, @payload) = @_; |
38 | $self->connections->receive(@payload); |
39 | } |
40 | |
41 | 1; |