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