line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POSIX::RT::MQ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: MQ.pm,v 1.12 2003/01/28 07:10:03 ilja Exp $ |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
55212
|
use 5.006; |
|
5
|
|
|
|
|
48
|
|
6
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
110
|
|
7
|
5
|
|
|
5
|
|
43
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
167
|
|
8
|
5
|
|
|
5
|
|
28
|
use Carp 'croak'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
288
|
|
9
|
5
|
|
|
5
|
|
28
|
use Fcntl 'O_NONBLOCK'; |
|
5
|
|
|
|
|
26
|
|
|
5
|
|
|
|
|
5148
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require DynaLoader; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(DynaLoader); |
14
|
|
|
|
|
|
|
our $VERSION = '0.04_04'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
bootstrap POSIX::RT::MQ $VERSION; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub open |
19
|
|
|
|
|
|
|
{ |
20
|
29
|
|
|
29
|
1
|
270
|
my $proto = shift; |
21
|
29
|
50
|
33
|
|
|
145
|
(@_ >= 2 && @_ <= 4) |
22
|
|
|
|
|
|
|
or croak 'Usage: POSIX::RT::MQ->open(name, oflag [, mode [, attr]])'; |
23
|
|
|
|
|
|
|
|
24
|
29
|
|
|
|
|
73
|
my @args = @_; |
25
|
29
|
100
|
|
|
|
61
|
$args[2] = 0666 unless defined $args[2]; |
26
|
|
|
|
|
|
|
# work around 'using undefined value' warnings |
27
|
|
|
|
|
|
|
# todo: fix XS? |
28
|
29
|
100
|
|
|
|
89
|
delete $args[3] unless defined $args[3]; |
29
|
29
|
100
|
|
|
|
74
|
$args[3] = attr_pack($args[3]) if defined $args[3]; # pack attr |
30
|
|
|
|
|
|
|
|
31
|
29
|
100
|
|
|
|
597
|
defined(my $mqdes = mq_open(@args)) or return undef; |
32
|
27
|
|
33
|
|
|
120
|
my $class = ref($proto) || $proto; |
33
|
27
|
|
|
|
|
133
|
my $self = bless { name=>$args[0], mqdes=>$mqdes }, $class; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# get attributes and save for future references (in receive()) |
36
|
27
|
50
|
|
|
|
120
|
$self->{_saved_attr_} = $self->attr or return undef; |
37
|
|
|
|
|
|
|
|
38
|
27
|
|
|
|
|
85
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub unlink |
42
|
|
|
|
|
|
|
{ |
43
|
26
|
|
|
26
|
1
|
791
|
my $self = shift; |
44
|
26
|
100
|
|
|
|
61
|
if (ref $self) |
45
|
|
|
|
|
|
|
{ |
46
|
3
|
50
|
|
|
|
8
|
(@_ == 0) or croak 'Usage: $mq->unlink()'; |
47
|
3
|
|
|
|
|
27
|
my $rc = mq_unlink($self->{name}); |
48
|
3
|
100
|
|
|
|
10
|
$self->{name} = undef if defined $rc; |
49
|
3
|
|
|
|
|
8
|
return $rc; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else |
52
|
|
|
|
|
|
|
{ |
53
|
23
|
50
|
|
|
|
55
|
(@_ == 1) or croak 'Usage: POSIX::RT::MQ->unlink(name)'; |
54
|
23
|
|
|
|
|
347
|
return mq_unlink($_[0]); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub attr |
59
|
|
|
|
|
|
|
{ |
60
|
42
|
|
|
42
|
1
|
109
|
my $self = shift; |
61
|
42
|
50
|
33
|
|
|
180
|
(@_ >= 0 && @_ <= 1) or croak 'Usage: $mq->attr( [new_attr] )'; |
62
|
42
|
|
|
|
|
390
|
my $attr_packed = mq_attr( $self->{mqdes}, map {attr_pack($_)} @_ ); |
|
4
|
|
|
|
|
19
|
|
63
|
|
|
|
|
|
|
|
64
|
42
|
50
|
|
|
|
169
|
defined $attr_packed ? attr_unpack($attr_packed) : undef; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub send |
68
|
|
|
|
|
|
|
{ |
69
|
87
|
|
|
87
|
1
|
26993
|
my $self = shift; |
70
|
87
|
50
|
33
|
|
|
354
|
(@_ >= 1 && @_ <= 2) or croak 'Usage: $mq->send($msg ,[ $prio ])'; |
71
|
87
|
|
100
|
|
|
3001697
|
return mq_send( $self->{mqdes}, $_[0], ($_[1] || 0) ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub receive |
75
|
|
|
|
|
|
|
{ |
76
|
67
|
|
|
67
|
1
|
639
|
my $self = shift; |
77
|
67
|
50
|
|
|
|
141
|
(@_ == 0) or croak 'Usage: $mq->receive()'; |
78
|
67
|
|
|
|
|
3001034
|
my @result = mq_receive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize}); |
79
|
67
|
100
|
|
|
|
388
|
wantarray ? @result : $result[0]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub notify |
83
|
|
|
|
|
|
|
{ |
84
|
5
|
|
|
5
|
1
|
139
|
my $self = shift; |
85
|
5
|
50
|
|
|
|
19
|
(@_ <= 1) or croak 'Usage: $mq->notify([ $signo ])'; |
86
|
5
|
|
|
|
|
60
|
mq_notify( $self->{mqdes}, @_ ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub blocking |
90
|
|
|
|
|
|
|
{ |
91
|
6
|
|
|
6
|
1
|
169621
|
my $self = shift; |
92
|
6
|
50
|
|
|
|
34
|
(@_ <= 1) or croak 'Usage: $mq->blocking([ BOOL ])'; |
93
|
|
|
|
|
|
|
|
94
|
6
|
50
|
|
|
|
25
|
my $a = $self->attr() or return undef; |
95
|
6
|
100
|
|
|
|
42
|
my $old_blocking = ($a->{mq_flags} & O_NONBLOCK) ? 0 : 1; |
96
|
6
|
100
|
|
|
|
82
|
if (@_) |
97
|
|
|
|
|
|
|
{ |
98
|
3
|
100
|
|
|
|
41
|
if ($_[0]) { $a->{mq_flags} &= (~O_NONBLOCK); } |
|
1
|
|
|
|
|
3
|
|
99
|
2
|
|
|
|
|
11
|
else { $a->{mq_flags} |= O_NONBLOCK; } |
100
|
|
|
|
|
|
|
|
101
|
3
|
50
|
|
|
|
17
|
$self->attr($a) or $old_blocking = undef;; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
33
|
$old_blocking; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
2
|
1
|
11
|
sub name { $_[0]->{name} } |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# expose mqdes |
110
|
0
|
|
|
0
|
0
|
0
|
sub mqdes { $_[0]->{mqdes} } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub DESTROY |
113
|
|
|
|
|
|
|
{ |
114
|
27
|
|
|
27
|
|
1803
|
my $self = shift; |
115
|
|
|
|
|
|
|
#print "destrsroying $self\n"; |
116
|
27
|
50
|
|
|
|
346
|
defined($self->{mqdes}) and mq_close($self->{mqdes}); |
117
|
27
|
|
|
|
|
511
|
$self->{mqdes} = undef; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# allow explicit close |
121
|
|
|
|
|
|
|
*close = \&DESTROY; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub attr_pack |
124
|
|
|
|
|
|
|
{ |
125
|
22
|
|
|
22
|
0
|
63
|
my $as_hash = shift; |
126
|
22
|
100
|
|
|
|
50
|
mq_attr_pack( map {defined $as_hash->{$_} ? $as_hash->{$_} : 0} |
|
88
|
|
|
|
|
303
|
|
127
|
|
|
|
|
|
|
qw/mq_flags mq_maxmsg mq_msgsize mq_curmsgs/ ); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub attr_unpack |
132
|
|
|
|
|
|
|
{ |
133
|
42
|
|
|
42
|
0
|
129
|
my @attr = mq_attr_unpack(shift); |
134
|
42
|
|
|
|
|
259
|
{ mq_flags=>$attr[0], mq_maxmsg=>$attr[1], mq_msgsize=>$attr[2], mq_curmsgs=>$attr[3] }; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |