| 1 |
root |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use Coro; |
| 4 |
|
|
use Coro::Event; |
| 5 |
|
|
|
| 6 |
root |
1.4 |
$Event::DebugLevel = 4; |
| 7 |
|
|
|
| 8 |
root |
1.2 |
my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r'); |
| 9 |
|
|
|
| 10 |
root |
1.4 |
sub finger { |
| 11 |
|
|
my $host = shift; |
| 12 |
|
|
my $user = shift; |
| 13 |
|
|
use IO::Socket::INET; |
| 14 |
|
|
# is there ANY way to do non-blocking connects with IO::Socket::INET? |
| 15 |
|
|
# I don't see how... |
| 16 |
|
|
my $io = new IO::Socket::INET PeerAddr => "$host:finger"; |
| 17 |
|
|
syswrite $io, "$user\n"; |
| 18 |
|
|
#do_timer(after => 5); |
| 19 |
|
|
my $r = Coro::Event->io(fd => $io, poll => 'r'); |
| 20 |
|
|
my $buf; |
| 21 |
|
|
$r->next while 0 != sysread $io, $buf, 8192, length $buf; |
| 22 |
|
|
#do_timer(after => 5); |
| 23 |
|
|
print $buf; |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
root |
1.2 |
sub kbdline { |
| 27 |
|
|
$stdin->next; |
| 28 |
|
|
my $x = <STDIN>; chomp $x; $x; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
root |
1.1 |
sub keyboard : Coro { |
| 32 |
root |
1.2 |
$|=1; |
| 33 |
|
|
while() { |
| 34 |
|
|
print "cmd> "; my $cmd = kbdline; |
| 35 |
root |
1.4 |
if ($cmd eq "finger") { |
| 36 |
|
|
print "user> "; my $user = kbdline; |
| 37 |
|
|
print "host> "; my $host = kbdline; |
| 38 |
|
|
async sub { finger($host, $user) }; |
| 39 |
|
|
} elsif ($cmd eq "quit") { |
| 40 |
|
|
unloop(777); |
| 41 |
|
|
terminate; |
| 42 |
|
|
} else { |
| 43 |
|
|
print "enter command, either 'finger' or 'quit'\n"; |
| 44 |
|
|
} |
| 45 |
root |
1.2 |
} |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
root |
1.4 |
sub timer : Coro { |
| 49 |
|
|
my $w = Coro::Event->timer(interval => 0.1, hard => 1); |
| 50 |
|
|
use Time::HiRes qw(time); |
| 51 |
root |
1.2 |
while () { |
| 52 |
|
|
$w->next; |
| 53 |
root |
1.4 |
print "\e7\e[A\10\10\10 <time ",time,"> \e8"; |
| 54 |
root |
1.2 |
}; |
| 55 |
root |
1.1 |
} |
| 56 |
root |
1.2 |
|
| 57 |
root |
1.4 |
print "unlooped with value: ",loop(),"\n"; |
| 58 |
root |
1.1 |
|