|  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
  
 | 
 
 | 
55177
 | 
 use 5.006;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
    | 
| 
6
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
25
 | 
 use strict;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
99
 | 
    | 
| 
7
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
23
 | 
 use warnings;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
168
 | 
    | 
| 
8
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
25
 | 
 use Carp 'croak';  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
278
 | 
    | 
| 
9
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
28
 | 
 use Fcntl 'O_NONBLOCK';  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5594
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 require DynaLoader;  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @ISA = qw(DynaLoader);  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.05';  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 bootstrap POSIX::RT::MQ $VERSION;  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub open  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
20
 | 
30
 | 
 
 | 
 
 | 
  
30
  
 | 
  
1
  
 | 
242
 | 
     my $proto  = shift;  | 
| 
21
 | 
30
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
159
 | 
     (@_ >= 2 && @_ <= 4)  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         or croak 'Usage: POSIX::RT::MQ->open(name, oflag [, mode [, attr]])';  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
24
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
81
 | 
     my @args = @_;  | 
| 
25
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
65
 | 
     $args[2] = 0666                 unless defined $args[2];  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # work around 'using undefined value' warnings  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # todo: fix XS?  | 
| 
28
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
71
 | 
     delete $args[3] unless defined $args[3];  | 
| 
29
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
77
 | 
     $args[3] = attr_pack($args[3])  if     defined $args[3]; # pack attr  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
31
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
597
 | 
     defined(my $mqdes  = mq_open(@args))  or return undef;  | 
| 
32
 | 
28
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
125
 | 
     my $class  = ref($proto) || $proto;  | 
| 
33
 | 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
108
 | 
     my $self   = bless { name=>$args[0], mqdes=>$mqdes }, $class;  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # get attributes and save for future references (in receive())  | 
| 
36
 | 
28
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
125
 | 
     $self->{_saved_attr_} = $self->attr  or return undef;  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
38
 | 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
91
 | 
     return $self;  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub unlink   | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {   | 
| 
43
 | 
27
 | 
 
 | 
 
 | 
  
27
  
 | 
  
1
  
 | 
862
 | 
     my $self  = shift;  | 
| 
44
 | 
27
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
63
 | 
     if (ref $self)  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     {  | 
| 
46
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
         (@_ == 0) or croak 'Usage: $mq->unlink()';  | 
| 
47
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
28
 | 
         my $rc = mq_unlink($self->{name});  | 
| 
48
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         $self->{name} = undef  if defined $rc;  | 
| 
49
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         return $rc;  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     {  | 
| 
53
 | 
24
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
63
 | 
         (@_ == 1) or croak 'Usage: POSIX::RT::MQ->unlink(name)';  | 
| 
54
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
391
 | 
         return mq_unlink($_[0]);  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub attr  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
60
 | 
43
 | 
 
 | 
 
 | 
  
43
  
 | 
  
1
  
 | 
92
 | 
     my $self = shift;  | 
| 
61
 | 
43
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
178
 | 
     (@_ >= 0 && @_ <= 1) or croak 'Usage: $mq->attr( [new_attr] )';  | 
| 
62
 | 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
400
 | 
     my $attr_packed = mq_attr( $self->{mqdes}, map {attr_pack($_)} @_ );  | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
    | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
64
 | 
43
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
162
 | 
     defined $attr_packed ? attr_unpack($attr_packed) : undef;  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub send  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {   | 
| 
69
 | 
88
 | 
 
 | 
 
 | 
  
88
  
 | 
  
1
  
 | 
25763
 | 
     my $self = shift;  | 
| 
70
 | 
88
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
357
 | 
     (@_ >= 1 && @_ <= 2) or croak 'Usage: $mq->send($msg ,[ $prio ])';  | 
| 
71
 | 
88
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
3001315
 | 
     return mq_send( $self->{mqdes}, $_[0], ($_[1] || 0) );  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub receive   | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {   | 
| 
76
 | 
67
 | 
 
 | 
 
 | 
  
67
  
 | 
  
1
  
 | 
653
 | 
     my $self = shift;  | 
| 
77
 | 
67
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
133
 | 
     (@_ == 0) or croak 'Usage: $mq->receive()';  | 
| 
78
 | 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3000723
 | 
     my @result = mq_receive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize});  | 
| 
79
 | 
67
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
359
 | 
     wantarray ? @result : $result[0];  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub timedreceive  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
84
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
1
  
 | 
82
 | 
     my $self = shift;  | 
| 
85
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     (@_ <= 1) or croak 'Usage: $mq->timedreceive([ $time_in_seconds] )';  | 
| 
86
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1000115
 | 
     my @result = mq_timedreceive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize}, @_ );  | 
| 
87
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
34
 | 
     wantarray ? @result : $result[0];  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub notify  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {   | 
| 
92
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
  
1
  
 | 
116
 | 
     my $self = shift;  | 
| 
93
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
17
 | 
     (@_ <= 1) or croak 'Usage: $mq->notify([ $signo ])';  | 
| 
94
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
     mq_notify( $self->{mqdes}, @_ );  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub blocking  | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
99
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
164675
 | 
     my $self = shift;  | 
| 
100
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
39
 | 
     (@_ <= 1) or croak 'Usage: $mq->blocking([ BOOL ])';  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
102
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     my $a = $self->attr()  or return undef;  | 
| 
103
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
43
 | 
     my $old_blocking = ($a->{mq_flags} & O_NONBLOCK) ? 0 : 1;  | 
| 
104
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
35
 | 
     if (@_)   | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     {  | 
| 
106
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
         if ($_[0]) { $a->{mq_flags} &= (~O_NONBLOCK); }  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
107
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
         else       { $a->{mq_flags} |= O_NONBLOCK;    }  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
109
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
22
 | 
         $self->attr($a) or $old_blocking = undef;;  | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
112
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     $old_blocking;  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
115
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
1
  
 | 
12
 | 
 sub name { $_[0]->{name} }  | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # expose mqdes  | 
| 
118
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
0
  
 | 
0
 | 
 sub mqdes { $_[0]->{mqdes} }  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub DESTROY  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {   | 
| 
122
 | 
28
 | 
 
 | 
 
 | 
  
28
  
 | 
 
 | 
1573
 | 
     my $self  = shift;  | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     #print "destrsroying $self\n";  | 
| 
124
 | 
28
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
348
 | 
     defined($self->{mqdes}) and mq_close($self->{mqdes});  | 
| 
125
 | 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
597
 | 
     $self->{mqdes} = undef;  | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }      | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # allow explicit close  | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 *close = \&DESTROY;  | 
| 
130
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
131
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub attr_pack  | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
133
 | 
23
 | 
 
 | 
 
 | 
  
23
  
 | 
  
0
  
 | 
38
 | 
     my $as_hash = shift;  | 
| 
134
 | 
23
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
47
 | 
     mq_attr_pack( map {defined $as_hash->{$_} ? $as_hash->{$_} : 0}   | 
| 
 
 | 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
304
 | 
    | 
| 
135
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                       qw/mq_flags mq_maxmsg mq_msgsize mq_curmsgs/ );  | 
| 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
138
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub attr_unpack  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
141
 | 
43
 | 
 
 | 
 
 | 
  
43
  
 | 
  
0
  
 | 
136
 | 
     my @attr = mq_attr_unpack(shift);  | 
| 
142
 | 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
233
 | 
     { mq_flags=>$attr[0], mq_maxmsg=>$attr[1], mq_msgsize=>$attr[2], mq_curmsgs=>$attr[3] };  | 
| 
143
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
144
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
146
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
147
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |