X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTak%2FSTDIOSetup.pm;h=dcf0dc49fa52fefce1f9cee890d32a256a31ef0d;hb=2791fd73b196072f047b2b3d746b64be53312ca3;hp=fed46569a393e4dec1750c6d9abb2525fa7f7316;hpb=77bf1d9b5b6832894676ab549ee5664cb7200d33;p=scpubgit%2FTak.git diff --git a/lib/Tak/STDIOSetup.pm b/lib/Tak/STDIOSetup.pm index fed4656..dcf0dc4 100644 --- a/lib/Tak/STDIOSetup.pm +++ b/lib/Tak/STDIOSetup.pm @@ -8,12 +8,22 @@ use strictures 1; sub run { open my $stdin, '<&', \*STDIN; open my $stdout, '>&', \*STDOUT; - close STDIN; close STDOUT; + # if we don't re-open them then 0 and 1 get re-used - which is not + # only potentially bloody confusing but results in warnings like: + # "Filehandle STDOUT reopened as STDIN only for input" + close STDIN; open STDIN, '<', '/dev/null'; + close STDOUT; open STDOUT, '>', '/dev/null'; + my $done; my $connection = Tak::ConnectionService->new( read_fh => $stdin, write_fh => $stdout, - listening_service => Tak::Router->new + listening_service => Tak::Router->new, + on_close => sub { $done = 1 } ); - Tak->loop->loop_forever; + $connection->receiver->service->register_weak(remote => $connection); + if ($0 eq '-') { + $0 = 'tak-stdio-node'; + } + Tak->loop_until($done); } 1;