MQ.xs

filter: Statementstmt 96.4% 54 / 56 Branchbran 65.1% 43 / 66 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 79.5% 97 / 122 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/POSIX/RT/MQ.pm ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include <mqueue.h>
6 #include <signal.h>
7 #include <unistd.h>
8  
9 static char cvs_id[] = "$Id: MQ.xs,v 1.8 2003/01/27 10:43:11 ilja Exp $";
10  
11 0 static int not_here(char *s)
12 {
13 0 croak("POSIX::RT::MQ::%s not implemented on this architecture", s);
14 return -1;
15 }
16  
17 MODULE = POSIX::RT::MQ PACKAGE = POSIX::RT::MQ
18 PROTOTYPES: ENABLE
19  
20 int
21 MQ_OPEN_MAX()
22 PREINIT:
23 1 ▶ int val=-1;
Branch: 1 branch
BranchTrueFalseTotal
int val=-1; 1 0 1
24 CODE:
25 1 errno = 0;
26 #ifdef _SC_MQ_OPEN_MAX
27 1 val = sysconf(_SC_MQ_OPEN_MAX);
28 #endif
29 /* if errno is still 0 the limit is indeterminate */
30 1 ▶ if (errno && val==-1) not_here("MQ_OPEN_MAX");
Branch: 2 branches
BranchTrueFalseTotal
if (errno && val==-1) not_here("MQ_OPEN_MAX"); 0 1 1
if (errno && val==-1) not_here("MQ_OPEN_MAX"); 0 0 0
31 1 ▶ RETVAL=val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL=val; 0 1 1
32 OUTPUT:
33 RETVAL
34  
35 int
36 MQ_PRIO_MAX()
37 PREINIT:
38 1 ▶ int val=-1;
Branch: 1 branch
BranchTrueFalseTotal
int val=-1; 1 0 1
39 CODE:
40 1 errno = 0;
41 #ifdef _SC_MQ_PRIO_MAX
42 1 val = sysconf(_SC_MQ_PRIO_MAX);
43 #endif
44 /* if errno is still 0 the limit is indeterminate */
45 1 ▶ if (errno && val==-1) not_here("MQ_PRIO_MAX");
Branch: 2 branches
BranchTrueFalseTotal
if (errno && val==-1) not_here("MQ_PRIO_MAX"); 0 1 1
if (errno && val==-1) not_here("MQ_PRIO_MAX"); 0 0 0
46 1 ▶ RETVAL=val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL=val; 0 1 1
47 OUTPUT:
48 RETVAL
49  
50  
51  
52 mqd_t
53 mq_open(name,oflag,mode,attr=NULL)
54 char* name
55 int oflag
56 Mode_t mode
57 SV* attr
58 PREINIT:
59 mqd_t mqdes;
60 29 ▶ struct mq_attr* mqa_ptr = NULL;
Branch: 1 branch
BranchTrueFalseTotal
struct mq_attr* mqa_ptr = NULL; 29 0 29
61 STRLEN mqa_len;
62 CODE:
63 29 ▶ if (attr != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (attr != NULL) 18 11 29
64 18 mqa_ptr = (struct mq_attr*) SvPV(attr, mqa_len);
65 /* check mqa_len ? */
66 29 mqdes = mq_open(name, oflag, mode, mqa_ptr);
67 29 ▶ if (mqdes == (mqd_t)-1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mqdes == (mqd_t)-1) { XSRETURN_UNDEF; } 2 27 29
68 27 ▶ RETVAL = mqdes;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = mqdes; 23 4 27
69 OUTPUT:
70 RETVAL
71  
72 int
73 mq_close(mqdes)
74 mqd_t mqdes
75 CODE:
76 27 ▶ if (mq_close(mqdes) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_close(mqdes) == -1) { XSRETURN_UNDEF; } 0 27 27
77 27 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 23 4 27
78 OUTPUT:
79 RETVAL
80  
81 int
82 mq_unlink(name)
83 char* name
84 CODE:
85 26 ▶ if (mq_unlink(name) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_unlink(name) == -1) { XSRETURN_UNDEF; } 5 21 26
86 21 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 16 5 21
87 OUTPUT:
88 RETVAL
89  
90 SV*
91 mq_attr(mqdes, new_attr=NULL)
92 mqd_t mqdes
93 SV* new_attr;
94 PREINIT:
95 struct mq_attr old_mqa;
96 struct mq_attr* new_mqa_ptr;
97 STRLEN new_mqa_len;
98 CODE:
99 42 ▶ if (new_attr == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (new_attr == NULL) 38 4 42
100 {
101 38 ▶ if (mq_getattr(mqdes, &old_mqa) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_getattr(mqdes, &old_mqa) == -1) { XSRETURN_UNDEF; } 0 38 38
102 }
103 else
104 {
105 4 new_mqa_ptr = (struct mq_attr*) SvPV(new_attr, new_mqa_len);
106 /* check new_mqa_len ? */
107 4 ▶ if (mq_setattr(mqdes, new_mqa_ptr, &old_mqa) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_setattr(mqdes, new_mqa_ptr, &old_mqa) == -1) { XSRETURN_UNDEF; } 0 4 4
108 }
109 42 RETVAL = newSVpvn((char*)&old_mqa, sizeof(old_mqa));
110 OUTPUT:
111 RETVAL
112
113 int
114 mq_send(mqdes, msg, msg_prio)
115 mqd_t mqdes
116 SV* msg
117 unsigned int msg_prio
118 PREINIT:
119 char* msg_ptr;
120 STRLEN msg_len;
121 CODE:
122 87 msg_ptr = SvPV(msg, msg_len);
123 87 ▶ if (mq_send(mqdes, msg_ptr, msg_len, msg_prio) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_send(mqdes, msg_ptr, msg_len, msg_prio) == -1) { XSRETURN_UNDEF; } 2 85 87
124 85 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 83 2 85
125 OUTPUT:
126 RETVAL
127  
128 void
129 mq_receive(mqdes, msg_max_len)
130 mqd_t mqdes
131 size_t msg_max_len
132 PREINIT:
133 char* msg_ptr;
134 ssize_t msg_len;
135 unsigned int msg_prio;
136 PPCODE:
137 67 ▶ if ((msg_ptr = malloc(msg_max_len)) == NULL) { XSRETURN_EMPTY; }
Branch: 1 branch
BranchTrueFalseTotal
if ((msg_ptr = malloc(msg_max_len)) == NULL) { XSRETURN_EMPTY; } 0 67 67
138 67 msg_len = mq_receive(mqdes, msg_ptr, msg_max_len, &msg_prio);
139 67 ▶ if (msg_len == -1)
Branch: 1 branch
BranchTrueFalseTotal
if (msg_len == -1) 2 65 67
140 {
141 2 free(msg_ptr);
142 2 XSRETURN_EMPTY;
143 }
144 65 ▶ XPUSHs(sv_2mortal(newSVpvn(msg_ptr, msg_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(msg_ptr, msg_len))); 0 65 65
145 65 ▶ XPUSHs(sv_2mortal(newSVuv(msg_prio)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv(msg_prio))); 0 65 65
146 65 free(msg_ptr);
147  
148 int
149 mq_notify(mqdes, ...)
150 mqd_t mqdes
151 PREINIT:
152 struct sigevent sigev;
153 5 ▶ struct sigevent* sigevp = NULL;
Branch: 1 branch
BranchTrueFalseTotal
struct sigevent* sigevp = NULL; 5 0 5
154 CODE:
155 5 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 2 3 5
156 {
157 2 sigev.sigev_notify = SIGEV_SIGNAL;
158 2 sigev.sigev_signo = SvIV(ST(1));
159 2 sigev.sigev_value.sival_int = 0;
160 2 sigevp = &sigev;
161 }
162 5 ▶ if (mq_notify(mqdes, sigevp) == -1) { XSRETURN_UNDEF; }
Branch: 1 branch
BranchTrueFalseTotal
if (mq_notify(mqdes, sigevp) == -1) { XSRETURN_UNDEF; } 0 5 5
163 5 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 3 2 5
164 OUTPUT:
165 RETVAL
166  
167  
168 SV*
169 mq_attr_pack(mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs)
170 long mq_flags
171 long mq_maxmsg
172 long mq_msgsize
173 long mq_curmsgs
174 PREINIT:
175 struct mq_attr mqa;
176 CODE:
177 22 mqa.mq_flags = mq_flags;
178 22 mqa.mq_maxmsg = mq_maxmsg;
179 22 mqa.mq_msgsize = mq_msgsize;
180 22 mqa.mq_curmsgs = mq_curmsgs;
181 22 RETVAL = newSVpvn((char*)&mqa, sizeof(mqa));
182 OUTPUT:
183 RETVAL
184  
185 void
186 mq_attr_unpack(mqa)
187 SV* mqa
188 PREINIT:
189 struct mq_attr* mqa_ptr;
190 STRLEN mqa_len;
191 PPCODE:
192 42 mqa_ptr = (struct mq_attr*) SvPV(mqa, mqa_len);
193 /* check mqa_len ? */
194 42 ▶ XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_flags)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_flags))); 0 42 42
195 42 ▶ XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_maxmsg)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_maxmsg))); 0 42 42
196 42 ▶ XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_msgsize)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_msgsize))); 0 42 42
197 42 ▶ XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_curmsgs)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_curmsgs))); 0 42 42
« blib/lib/POSIX/RT/MQ.pm ↑ Summary