line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::ZeroMQ; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
35429
|
$AnyEvent::ZeroMQ::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: non-blocking interface to ZeroMQ sockets |
6
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1736
|
use ZeroMQ::Raw; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use ZeroMQ::Raw::Constants qw(ZMQ_FD ZMQ_POLLIN ZMQ_POLLOUT ZMQ_EVENTS); |
11
|
|
|
|
|
|
|
use Carp qw(confess); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use namespace::autoclean; |
14
|
|
|
|
|
|
|
use AnyEvent; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub io { |
17
|
|
|
|
|
|
|
my ($class, %args) = @_; |
18
|
|
|
|
|
|
|
my $poll = $args{poll} || confess 'must supply poll direction'; |
19
|
|
|
|
|
|
|
my $sock = $args{socket} || confess 'must supply socket'; |
20
|
|
|
|
|
|
|
my $cb = $args{cb} || confess 'must supply cb'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $fd = $sock->getsockopt(ZMQ_FD); |
23
|
|
|
|
|
|
|
confess 'getsockopt did not return a valid fd!' |
24
|
|
|
|
|
|
|
unless defined $fd; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $mask = $poll eq 'w' ? ZMQ_POLLOUT : |
27
|
|
|
|
|
|
|
$poll eq 'r' ? ZMQ_POLLIN : |
28
|
|
|
|
|
|
|
confess "invalid poll direction '$poll'"; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return AnyEvent->io( |
31
|
|
|
|
|
|
|
poll => $poll, |
32
|
|
|
|
|
|
|
fh => $fd, |
33
|
|
|
|
|
|
|
cb => sub { |
34
|
|
|
|
|
|
|
$cb->() if (($sock->getsockopt(ZMQ_EVENTS) & $mask) == $mask); |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub probe { |
40
|
|
|
|
|
|
|
my ($class, %args) = @_; |
41
|
|
|
|
|
|
|
my $poll = $args{poll} || confess 'must supply poll direction'; |
42
|
|
|
|
|
|
|
my $sock = $args{socket} || confess 'must supply socket'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $mask = $poll eq 'w' ? ZMQ_POLLOUT : |
45
|
|
|
|
|
|
|
$poll eq 'r' ? ZMQ_POLLIN : |
46
|
|
|
|
|
|
|
confess "invalid poll direction '$poll'"; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return (($sock->getsockopt(ZMQ_EVENTS) & $mask) == $mask) |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
54
|
|
|
|
|
|
|
=pod |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
AnyEvent::ZeroMQ - non-blocking interface to ZeroMQ sockets |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 VERSION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
version 0.01 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 AUTHOR |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Jonathan Rockway <jrockway@cpan.org> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Jonathan Rockway. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
73
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|