Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-Coro/eg/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Coro/eg/event
#!/usr/bin/perl

# this crap is an asynchronous finger client. it's rather idiotic ;)

use Coro;
use Coro::Socket;
use Coro::Event;
use AnyEvent;

my $quit = AnyEvent->condvar;

# this gets started everytime a user enters a finger command
sub finger {
   my $user = shift;
   my $host = shift;

   my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger"
      or die "$user\@$host: $!";

   print $fh "$user\n";

   print "$user\@$host: $_" while <$fh>;
   print "$user\@$host: done\n";
}

# display the time or garble the display, YMMV.
async {
   my $w = Coro::Event->timer (interval => 0.001, hard => 1);
   use Time::HiRes qw(time);
   while () {
      $w->next;
      print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C   <time ", time, ">   \e8";
   };
};

my $stdin = new_from_fh Coro::Handle \*STDIN;

$SIG{PIPE} = 'IGNORE';

$| = 1;
while() {
   print "cmd (finger|quit)> "; my $cmd = <$stdin>; chomp $cmd;
   if ($cmd eq "finger") {
      print "user> "; my $user = <$stdin>; chomp $user;
      print "host> "; my $host = <$stdin>; chomp $host;
      async { finger $user, $host };
   } elsif ($cmd eq "quit") {
      last;
   } else {
      print "unknown command '$cmd', either 'finger' or 'quit'\n";
   }
}


Hry