Commit | Line | Data |
77bf1d9b |
1 | package Tak::STDIOSetup; |
2 | |
e99bc141 |
3 | BEGIN { require MRO::Compat; } |
4 | |
77bf1d9b |
5 | use Tak::ConnectionService; |
6 | use Tak::Router; |
7 | use Tak; |
8 | use strictures 1; |
9 | |
10 | sub run { |
11 | open my $stdin, '<&', \*STDIN; |
12 | open my $stdout, '>&', \*STDOUT; |
2791fd73 |
13 | # if we don't re-open them then 0 and 1 get re-used - which is not |
14 | # only potentially bloody confusing but results in warnings like: |
15 | # "Filehandle STDOUT reopened as STDIN only for input" |
16 | close STDIN; open STDIN, '<', '/dev/null'; |
17 | close STDOUT; open STDOUT, '>', '/dev/null'; |
986f5290 |
18 | my $done; |
77bf1d9b |
19 | my $connection = Tak::ConnectionService->new( |
20 | read_fh => $stdin, write_fh => $stdout, |
986f5290 |
21 | listening_service => Tak::Router->new, |
22 | on_close => sub { $done = 1 } |
77bf1d9b |
23 | ); |
2791fd73 |
24 | $connection->receiver->service->register_weak(remote => $connection); |
25 | if ($0 eq '-') { |
26 | $0 = 'tak-stdio-node'; |
27 | } |
986f5290 |
28 | Tak->loop_until($done); |
77bf1d9b |
29 | } |
30 | |
31 | 1; |