#!/usr/bin/perl

use Coro;
use Coro::Event;

my $stdin = Coro::Event->io(fd => \*STDIN, poll => 'r');

sub kbdline {
   $stdin->next;
   my $x = <STDIN>; chomp $x; $x;
}

sub keyboard : Coro {
   $|=1;
   while() {
      print "cmd> ";  my $cmd  = kbdline;
      print "data> "; my $data = kbdline;
      print "cmd<$cmd> data<$data>\n";
      print "working...";
      do_timer(after => 1);
      print "done\n";
   }
}

sub idle : Coro {
   my $w = Coro::Event->idle(min => 1, max => 2);
   while () {
      $w->next;
      print ".";
   };
}

sub finger : Coro {
   use IO::Socket::INET;
   # is there ANY way to do non-blocking connects with IO::Socket::INET?
   # I don't see how...
   my $io = new IO::Socket::INET PeerAddr => "noc.dfn.de:finger";
   print "connected, sending\n";
   syswrite $io, "trouble\n";
   my $r = Coro::Event->io(fd => $io, poll => 'r');
   my $buf;
   $r->next while 0 != sysread $io, $buf, 8192, length $buf;
   print $buf;
   do_timer(after => 60);
}

Coro::Event->main;

