1 ################################################################################
3 # Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz <mhx@cpan.org>.
4 # Version 1.x, Copyright (C) 1999, Graham Barr <gbarr@pobox.com>.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the same terms as Perl itself.
9 ################################################################################
16 if ($ENV{'PERL_CORE'}) {
18 @INC = '../lib' if -d '../lib' && -d '../ext';
21 require Test::More; import Test::More;
22 require Config; import Config;
24 if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
25 plan(skip_all => 'IPC::SysV was not built');
29 if ($Config{'d_sem'} ne 'define') {
30 plan(skip_all => '$Config{d_sem} undefined');
31 } elsif ($Config{'d_msg'} ne 'define') {
32 plan(skip_all => '$Config{d_msg} undefined');
35 use IPC::SysV qw(IPC_PRIVATE IPC_RMID IPC_NOWAIT IPC_STAT S_IRWXU S_IRWXG S_IRWXO);
38 #Creating a message queue
42 if (exists $SIG{SYS}) {
43 local $SIG{SYS} = sub { plan(skip_all => "SIGSYS caught") };
47 }->(sub { new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO) });
49 unless (defined $msq) {
50 my $info = "IPC::Msg->new failed: $!";
51 if ($! == &IPC::SysV::ENOSPC || $! == &IPC::SysV::ENOSYS ||
52 $! == &IPC::SysV::ENOMEM || $! == &IPC::SysV::EACCES) {
53 plan(skip_all => $info);
62 pass('create message queue');
64 #Putting a message on the queue
65 my $test_name = 'enqueue message';
69 if ($msq->snd($msgtype,$msg,IPC_NOWAIT)) {
77 #Check if there are messages on the queue
82 is($ds->qnum, 1, 'qnum');
88 #Retrieving a message from the queue
90 my $rmsgtype = 0; # Give me any type
91 $rmsgtype = $msq->rcv($rmsg,256,$rmsgtype,IPC_NOWAIT);
92 is($rmsgtype, $msgtype, 'rmsgtype');
93 is($rmsg, $msg, 'rmsg');
99 is($ds->qnum, 0, 'qnum');
106 ok($msq->remove, 'remove message') if defined $msq;