HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/libevent-perl/examples/echo.t
#!/usr/bin/perl -w

$| = 1;
use Event qw(time);
require Event::io;

print "This demo echoes whatever you type.  If you don't type anything
for as long as 2.5 seconds then it will complain.  Enter an empty line
to exit.

";

my $recent = time;
Event->io(fd      => \*STDIN,
          timeout => 2.5,
          poll    => "r",
          repeat  => 1,
          cb      => sub {
	      my $e = shift;
	      my $got = $e->got;
              #print scalar(localtime), " ";
	      if ($got eq "r") {
		  sysread(STDIN, $buf, 80);
		  chop $buf;
		  my $len = length($buf);
		  Event::unloop if !$len;
		  print "read[$len]:$buf:\n";
		  $recent = time;
	      } else {
		  print "nothing for ".(time - $recent)." seconds\n";
	      }
          });

Event::loop();