1 | #! perl |
1 | #! perl |
2 | |
2 | |
|
|
3 | use Coro::Debug; |
3 | use IO::Socket; |
4 | use IO::Socket; |
4 | use Storable qw/nfreeze thaw/; |
5 | use Storable qw/nfreeze thaw/; |
5 | |
6 | |
6 | my %global; # for use by eval'ed commands |
7 | my %global; # for use by eval'ed commands |
7 | |
8 | |
… | |
… | |
40 | if (defined (my $cmd = <$fh>)) { |
41 | if (defined (my $cmd = <$fh>)) { |
41 | $cmd =~ s/\s+$//; |
42 | $cmd =~ s/\s+$//; |
42 | |
43 | |
43 | if ($cmd =~ /^\s*exit\b/i) { |
44 | if ($cmd =~ /^\s*exit\b/i) { |
44 | print "will not exit() server.\n"; |
45 | print "will not exit() server.\n"; |
|
|
46 | } elsif ($cmd =~ s/^coro\s+// or $cmd =~ /^(?:ps|bt\s)/) { |
|
|
47 | Coro::Debug::command $cmd; |
45 | } else { |
48 | } else { |
46 | my $sub = sub { |
49 | my $sub = sub { |
47 | package cf; |
50 | package cf; |
48 | select $fh; |
51 | select $fh; |
49 | |
52 | |
… | |
… | |
62 | print "result:\n", cf::dumpval @res > 1 ? \@res : $res[0] if @res; |
65 | print "result:\n", cf::dumpval @res > 1 ? \@res : $res[0] if @res; |
63 | print "\n> "; |
66 | print "\n> "; |
64 | }; |
67 | }; |
65 | |
68 | |
66 | if ($cmd =~ s/\s*&$//) { |
69 | if ($cmd =~ s/\s*&$//) { |
67 | Coro::async { $sub->() }; |
70 | cf::async { |
|
|
71 | $Coro::current->desc ($cmd); |
|
|
72 | $sub->() |
|
|
73 | }; |
68 | } else { |
74 | } else { |
69 | $sub->(); |
75 | $sub->(); |
70 | } |
76 | } |
71 | } |
77 | } |
72 | |
78 | |
… | |
… | |
81 | if ($cf::CFG{perl_shell}) { |
87 | if ($cf::CFG{perl_shell}) { |
82 | if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1) { |
88 | if (my $listen = new IO::Socket::INET LocalAddr => $cf::CFG{perl_shell}, Listen => 1, ReuseAddr => 1) { |
83 | Event->io (fd => $listen, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { tcp_serve $listen->accept }); |
89 | Event->io (fd => $listen, poll => 'r', data => cf::WF_AUTOCANCEL, cb => sub { tcp_serve $listen->accept }); |
84 | } |
90 | } |
85 | } |
91 | } |
|
|
92 | |
|
|
93 | |