File: 20-tied.t

package info (click to toggle)
liblinux-epoll-perl 0.019-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: perl: 100; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! perl

use strict;
use warnings;

use Test::More;
use POSIX ();
use Linux::Epoll;

my $epoll = Linux::Epoll->new;

pipe my($in), my ($out);

tie *FH, 'TiedHandle', fileno $in;

my $colon = ':';
my $done;

$epoll->add(*FH, 'in', sub {
	my $events = shift;
	sysread FH, my $buf, 1;
	is($buf, $colon, 'Read a colon');
	$done = 1;
});

print $out $colon;
close $out;

alarm 3;
$epoll->wait(1, 1) while !$done;

ok($done, 'Received event');

done_testing(2);

package TiedHandle;

sub TIEHANDLE {
	my ($class, $fd) = @_;
	bless { fd => $fd }, $class;
}

sub FILENO {
	return $_[0]{fd};
}

sub READ {
	my ($self, undef, $count, undef) = @_;
	return POSIX::read($self->{fd}, $_[1], $count);
}