1 package Tak::STDIOSetup;
3 use Tak::ConnectionService;
9 open my $stdin, '<&', \*STDIN;
10 open my $stdout, '>&', \*STDOUT;
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';
17 my $connection = Tak::ConnectionService->new(
18 read_fh => $stdin, write_fh => $stdout,
19 listening_service => Tak::Router->new,
20 on_close => sub { $done = 1 }
22 $connection->receiver->service->register_weak(remote => $connection);
24 $0 = 'tak-stdio-node';
26 Tak->loop_until($done);