line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZMQ::FFI::Util; |
2
|
|
|
|
|
|
|
$ZMQ::FFI::Util::VERSION = '0.18'; |
3
|
|
|
|
|
|
|
# ABSTRACT: zmq convenience functions |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
93
|
use strict; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
819
|
|
6
|
14
|
|
|
14
|
|
81
|
use warnings; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
612
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
26169
|
use FFI::Raw; |
|
14
|
|
|
|
|
118575
|
|
|
14
|
|
|
|
|
605
|
|
9
|
14
|
|
|
14
|
|
128
|
use Carp; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
1513
|
|
10
|
14
|
|
|
14
|
|
10899
|
use Try::Tiny; |
|
14
|
|
|
|
|
24109
|
|
|
14
|
|
|
|
|
1447
|
|
11
|
|
|
|
|
|
|
|
12
|
14
|
|
|
|
|
150
|
use Sub::Exporter -setup => { |
13
|
|
|
|
|
|
|
exports => [qw( |
14
|
|
|
|
|
|
|
zmq_soname |
15
|
|
|
|
|
|
|
zmq_version |
16
|
|
|
|
|
|
|
)], |
17
|
14
|
|
|
14
|
|
20185
|
}; |
|
14
|
|
|
|
|
189202
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub zmq_soname { |
20
|
14
|
|
|
14
|
1
|
581
|
my %args = @_; |
21
|
|
|
|
|
|
|
|
22
|
14
|
|
|
|
|
55
|
my $die = $args{die}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Try to find a soname available on this system |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Linux .so symlink conventions are linker_name => soname => real_name |
27
|
|
|
|
|
|
|
# e.g. libzmq.so => libzmq.so.X => libzmq.so.X.Y.Z |
28
|
|
|
|
|
|
|
# Unfortunately not all distros follow this convention (Ubuntu). So first |
29
|
|
|
|
|
|
|
# we'll try the linker_name, then the sonames. |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# If Linux extensions fail also try platform specific |
32
|
|
|
|
|
|
|
# extensions (e.g. OS X) before giving up. |
33
|
14
|
|
|
|
|
187
|
my @sonames = qw( |
34
|
|
|
|
|
|
|
libzmq.so libzmq.so.4 libzmq.so.3 libzmq.so.1 |
35
|
|
|
|
|
|
|
libzmq.dylib libzmq.4.dylib libzmq.3.dylib libzmq.1.dylib |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
14
|
|
|
|
|
146
|
my $soname; |
39
|
|
|
|
|
|
|
FIND_SONAME: |
40
|
14
|
|
|
|
|
78
|
for (@sonames) { |
41
|
|
|
|
|
|
|
try { |
42
|
112
|
|
|
112
|
|
3593
|
$soname = $_; |
43
|
|
|
|
|
|
|
|
44
|
112
|
|
|
|
|
16209
|
my $zmq_version = FFI::Raw->new( |
45
|
|
|
|
|
|
|
$soname => 'zmq_version', |
46
|
|
|
|
|
|
|
FFI::Raw::void, |
47
|
|
|
|
|
|
|
FFI::Raw::ptr, # major |
48
|
|
|
|
|
|
|
FFI::Raw::ptr, # minor |
49
|
|
|
|
|
|
|
FFI::Raw::ptr # patch |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
catch { |
53
|
112
|
|
|
112
|
|
1631
|
undef $soname; |
54
|
112
|
|
|
|
|
1068
|
}; |
55
|
|
|
|
|
|
|
|
56
|
112
|
50
|
|
|
|
879
|
last FIND_SONAME if $soname; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
14
|
50
|
33
|
|
|
228
|
if ( !$soname && $die ) { |
60
|
14
|
|
|
|
|
4649
|
croak |
61
|
|
|
|
|
|
|
qq(Could not load libzmq, tried:\n), |
62
|
|
|
|
|
|
|
join(', ', @sonames),"\n", |
63
|
|
|
|
|
|
|
q(Is libzmq on your ld path?); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $soname; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub zmq_version { |
70
|
0
|
|
|
0
|
1
|
|
my $soname = shift; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$soname //= zmq_soname(); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return unless $soname; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $zmq_version = FFI::Raw->new( |
77
|
|
|
|
|
|
|
$soname => 'zmq_version', |
78
|
|
|
|
|
|
|
FFI::Raw::void, |
79
|
|
|
|
|
|
|
FFI::Raw::ptr, # major |
80
|
|
|
|
|
|
|
FFI::Raw::ptr, # minor |
81
|
|
|
|
|
|
|
FFI::Raw::ptr # patch |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my ($major, $minor, $patch) = map { pack 'i!', $_ } (0, 0, 0); |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @ptrs = map { unpack('L!', pack('P', $_)) } ($major, $minor, $patch); |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$zmq_version->(@ptrs); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return map { unpack 'i!', $_ } ($major, $minor, $patch); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |