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