1*0Sstevel@tonic-gate# IPC::Msg.pm 2*0Sstevel@tonic-gate# 3*0Sstevel@tonic-gate# Copyright (c) 1997 Graham Barr <gbarr@pobox.com>. All rights reserved. 4*0Sstevel@tonic-gate# This program is free software; you can redistribute it and/or 5*0Sstevel@tonic-gate# modify it under the same terms as Perl itself. 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gatepackage IPC::Msg; 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gateuse IPC::SysV qw(IPC_STAT IPC_SET IPC_RMID); 10*0Sstevel@tonic-gateuse strict; 11*0Sstevel@tonic-gateuse vars qw($VERSION); 12*0Sstevel@tonic-gateuse Carp; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate$VERSION = "1.02"; 15*0Sstevel@tonic-gate$VERSION = eval $VERSION; 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate{ 18*0Sstevel@tonic-gate package IPC::Msg::stat; 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate use Class::Struct qw(struct); 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate struct 'IPC::Msg::stat' => [ 23*0Sstevel@tonic-gate uid => '$', 24*0Sstevel@tonic-gate gid => '$', 25*0Sstevel@tonic-gate cuid => '$', 26*0Sstevel@tonic-gate cgid => '$', 27*0Sstevel@tonic-gate mode => '$', 28*0Sstevel@tonic-gate qnum => '$', 29*0Sstevel@tonic-gate qbytes => '$', 30*0Sstevel@tonic-gate lspid => '$', 31*0Sstevel@tonic-gate lrpid => '$', 32*0Sstevel@tonic-gate stime => '$', 33*0Sstevel@tonic-gate rtime => '$', 34*0Sstevel@tonic-gate ctime => '$', 35*0Sstevel@tonic-gate ]; 36*0Sstevel@tonic-gate} 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gatesub new { 39*0Sstevel@tonic-gate @_ == 3 || croak 'new IPC::Msg ( KEY , FLAGS )'; 40*0Sstevel@tonic-gate my $class = shift; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate my $id = msgget($_[0],$_[1]); 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate defined($id) 45*0Sstevel@tonic-gate ? bless \$id, $class 46*0Sstevel@tonic-gate : undef; 47*0Sstevel@tonic-gate} 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gatesub id { 50*0Sstevel@tonic-gate my $self = shift; 51*0Sstevel@tonic-gate $$self; 52*0Sstevel@tonic-gate} 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gatesub stat { 55*0Sstevel@tonic-gate my $self = shift; 56*0Sstevel@tonic-gate my $data = ""; 57*0Sstevel@tonic-gate msgctl($$self,IPC_STAT,$data) or 58*0Sstevel@tonic-gate return undef; 59*0Sstevel@tonic-gate IPC::Msg::stat->new->unpack($data); 60*0Sstevel@tonic-gate} 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gatesub set { 63*0Sstevel@tonic-gate my $self = shift; 64*0Sstevel@tonic-gate my $ds; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate if(@_ == 1) { 67*0Sstevel@tonic-gate $ds = shift; 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate else { 70*0Sstevel@tonic-gate croak 'Bad arg count' if @_ % 2; 71*0Sstevel@tonic-gate my %arg = @_; 72*0Sstevel@tonic-gate $ds = $self->stat 73*0Sstevel@tonic-gate or return undef; 74*0Sstevel@tonic-gate my($key,$val); 75*0Sstevel@tonic-gate $ds->$key($val) 76*0Sstevel@tonic-gate while(($key,$val) = each %arg); 77*0Sstevel@tonic-gate } 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate msgctl($$self,IPC_SET,$ds->pack); 80*0Sstevel@tonic-gate} 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gatesub remove { 83*0Sstevel@tonic-gate my $self = shift; 84*0Sstevel@tonic-gate (msgctl($$self,IPC_RMID,0), undef $$self)[0]; 85*0Sstevel@tonic-gate} 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gatesub rcv { 88*0Sstevel@tonic-gate @_ <= 5 && @_ >= 3 or croak '$msg->rcv( BUF, LEN, TYPE, FLAGS )'; 89*0Sstevel@tonic-gate my $self = shift; 90*0Sstevel@tonic-gate my $buf = ""; 91*0Sstevel@tonic-gate msgrcv($$self,$buf,$_[1],$_[2] || 0, $_[3] || 0) or 92*0Sstevel@tonic-gate return; 93*0Sstevel@tonic-gate my $type; 94*0Sstevel@tonic-gate ($type,$_[0]) = unpack("l! a*",$buf); 95*0Sstevel@tonic-gate $type; 96*0Sstevel@tonic-gate} 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gatesub snd { 99*0Sstevel@tonic-gate @_ <= 4 && @_ >= 3 or croak '$msg->snd( TYPE, BUF, FLAGS )'; 100*0Sstevel@tonic-gate my $self = shift; 101*0Sstevel@tonic-gate msgsnd($$self,pack("l! a*",$_[0],$_[1]), $_[2] || 0); 102*0Sstevel@tonic-gate} 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate1; 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate__END__ 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate=head1 NAME 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gateIPC::Msg - SysV Msg IPC object class 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate=head1 SYNOPSIS 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate use IPC::SysV qw(IPC_PRIVATE S_IRWXU); 116*0Sstevel@tonic-gate use IPC::Msg; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate $msg = new IPC::Msg(IPC_PRIVATE, S_IRWXU); 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate $msg->snd(pack("l! a*",$msgtype,$msg)); 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate $msg->rcv($buf,256); 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate $ds = $msg->stat; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate $msg->remove; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate=head1 DESCRIPTION 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gateA class providing an object based interface to SysV IPC message queues. 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate=head1 METHODS 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate=over 4 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate=item new ( KEY , FLAGS ) 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gateCreates a new message queue associated with C<KEY>. A new queue is 139*0Sstevel@tonic-gatecreated if 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate=over 4 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate=item * 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gateC<KEY> is equal to C<IPC_PRIVATE> 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate=item * 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gateC<KEY> does not already have a message queue 150*0Sstevel@tonic-gateassociated with it, and C<I<FLAGS> & IPC_CREAT> is true. 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate=back 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gateOn creation of a new message queue C<FLAGS> is used to set the 155*0Sstevel@tonic-gatepermissions. 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate=item id 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gateReturns the system message queue identifier. 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate=item rcv ( BUF, LEN [, TYPE [, FLAGS ]] ) 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gateRead a message from the queue. Returns the type of the message read. 164*0Sstevel@tonic-gateSee L<msgrcv>. The BUF becomes tainted. 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate=item remove 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gateRemove and destroy the message queue from the system. 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate=item set ( STAT ) 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate=item set ( NAME => VALUE [, NAME => VALUE ...] ) 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gateC<set> will set the following values of the C<stat> structure associated 175*0Sstevel@tonic-gatewith the message queue. 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate uid 178*0Sstevel@tonic-gate gid 179*0Sstevel@tonic-gate mode (oly the permission bits) 180*0Sstevel@tonic-gate qbytes 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gateC<set> accepts either a stat object, as returned by the C<stat> method, 183*0Sstevel@tonic-gateor a list of I<name>-I<value> pairs. 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate=item snd ( TYPE, MSG [, FLAGS ] ) 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gatePlace a message on the queue with the data from C<MSG> and with type C<TYPE>. 188*0Sstevel@tonic-gateSee L<msgsnd>. 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate=item stat 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gateReturns an object of type C<IPC::Msg::stat> which is a sub-class of 193*0Sstevel@tonic-gateC<Class::Struct>. It provides the following fields. For a description 194*0Sstevel@tonic-gateof these fields see you system documentation. 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate uid 197*0Sstevel@tonic-gate gid 198*0Sstevel@tonic-gate cuid 199*0Sstevel@tonic-gate cgid 200*0Sstevel@tonic-gate mode 201*0Sstevel@tonic-gate qnum 202*0Sstevel@tonic-gate qbytes 203*0Sstevel@tonic-gate lspid 204*0Sstevel@tonic-gate lrpid 205*0Sstevel@tonic-gate stime 206*0Sstevel@tonic-gate rtime 207*0Sstevel@tonic-gate ctime 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate=back 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate=head1 SEE ALSO 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gateL<IPC::SysV> L<Class::Struct> 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate=head1 AUTHOR 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gateGraham Barr <gbarr@pobox.com> 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate=head1 COPYRIGHT 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gateCopyright (c) 1997 Graham Barr. All rights reserved. 222*0Sstevel@tonic-gateThis program is free software; you can redistribute it and/or modify it 223*0Sstevel@tonic-gateunder the same terms as Perl itself. 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate=cut 226*0Sstevel@tonic-gate 227