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