1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Coro::Debug; |
3 | use Coro::Debug; |
4 | use IO::Socket; |
4 | use IO::Socket; |
5 | use Storable qw/nfreeze thaw/; |
|
|
6 | |
5 | |
7 | my %global; # for use by eval'ed commands |
6 | my %global; # for use by eval'ed commands |
8 | |
7 | |
9 | sub tcp_serve($) { |
8 | sub tcp_serve($) { |
10 | my ($fh) = @_; |
9 | my ($fh) = @_; |
… | |
… | |
37 | |
36 | |
38 | Event->io (fd => $fh, poll => 'r', data => 0, cb => sub { |
37 | Event->io (fd => $fh, poll => 'r', data => 0, cb => sub { |
39 | if (defined (my $cmd = <$fh>)) { |
38 | if (defined (my $cmd = <$fh>)) { |
40 | $cmd =~ s/\s+$//; |
39 | $cmd =~ s/\s+$//; |
41 | |
40 | |
42 | select $fh; |
|
|
43 | if ($cmd =~ /^\s*exit\b/i) { |
41 | if ($cmd =~ /^\s*exit\b/i) { |
44 | print "will not exit() server.\n"; |
42 | print $fh "will not exit() server.\n"; |
45 | } elsif ($cmd =~ s/^coro\s+// or $cmd =~ /^(?:ps|bt\s)/) { |
43 | } elsif ($cmd =~ s/^coro\s+// or $cmd =~ /^(?:ps|bt\s)/) { |
|
|
44 | select $fh; |
46 | Coro::Debug::command $cmd; |
45 | Coro::Debug::command $cmd; |
|
|
46 | select STDOUT; |
47 | } else { |
47 | } else { |
48 | my $sub = sub { |
48 | my $sub = sub { |
49 | package cf; |
49 | package cf; |
50 | select $fh; |
50 | select $fh; |
51 | |
51 | |
… | |
… | |
75 | } else { |
75 | } else { |
76 | $sub->(); |
76 | $sub->(); |
77 | } |
77 | } |
78 | } |
78 | } |
79 | |
79 | |
80 | print "\n> "; |
80 | print $fh "\n> "; |
81 | select STDOUT; |
|
|
82 | } else { |
81 | } else { |
83 | $_[0]->w->cancel; |
82 | $_[0]->w->cancel; |
84 | } |
83 | } |
85 | }); |
84 | }); |
86 | } |
85 | } |