| 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 |
1 |
| static int not_here(char *s) |
| 12 |
|
| { |
| 13 |
1 |
| 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
| Branch | True | False | Total |
| int val=-1; |
1 |
0 |
1 |
|
| 24 |
|
| CODE: |
| 25 |
|
| #ifdef _SC_MQ_OPEN_MAX |
| 26 |
1 |
| val = sysconf(_SC_MQ_OPEN_MAX); |
| 27 |
|
| #endif |
| 28 |
1 |
▶ | if (val==-1) not_here("MQ_OPEN_MAX"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (val==-1) not_here("MQ_OPEN_MAX"); |
1 |
0 |
1 |
|
| 29 |
0 |
▶ | RETVAL=val; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL=val; |
0 |
0 |
0 |
|
| 30 |
|
| OUTPUT: |
| 31 |
|
| RETVAL |
| 32 |
|
| |
| 33 |
|
| int |
| 34 |
|
| MQ_PRIO_MAX() |
| 35 |
|
| PREINIT: |
| 36 |
1 |
▶ | int val=-1; |
Branch: 1 branch
| Branch | True | False | Total |
| int val=-1; |
1 |
0 |
1 |
|
| 37 |
|
| CODE: |
| 38 |
|
| #ifdef _SC_MQ_PRIO_MAX |
| 39 |
1 |
| val = sysconf(_SC_MQ_PRIO_MAX); |
| 40 |
|
| #endif |
| 41 |
1 |
▶ | if (val==-1) not_here("MQ_PRIO_MAX"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (val==-1) not_here("MQ_PRIO_MAX"); |
0 |
1 |
1 |
|
| 42 |
1 |
▶ | RETVAL=val; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL=val; |
0 |
1 |
1 |
|
| 43 |
|
| OUTPUT: |
| 44 |
|
| RETVAL |
| 45 |
|
| |
| 46 |
|
| |
| 47 |
|
| |
| 48 |
|
| mqd_t |
| 49 |
|
| mq_open(name,oflag,mode,attr=NULL) |
| 50 |
|
| char* name |
| 51 |
|
| int oflag |
| 52 |
|
| Mode_t mode |
| 53 |
|
| SV* attr |
| 54 |
|
| PREINIT: |
| 55 |
|
| mqd_t mqdes; |
| 56 |
24 |
▶ | struct mq_attr* mqa_ptr = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| struct mq_attr* mqa_ptr = NULL; |
24 |
0 |
24 |
|
| 57 |
|
| STRLEN mqa_len; |
| 58 |
|
| CODE: |
| 59 |
24 |
▶ | if (attr != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (attr != NULL) |
14 |
10 |
24 |
|
| 60 |
14 |
| mqa_ptr = (struct mq_attr*) SvPV(attr, mqa_len); |
| 61 |
|
| /* check mqa_len ? */ |
| 62 |
24 |
| mqdes = mq_open(name, oflag, mode, mqa_ptr); |
| 63 |
24 |
▶ | if (mqdes == (mqd_t)-1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mqdes == (mqd_t)-1) { XSRETURN_UNDEF; } |
8 |
16 |
24 |
|
| 64 |
16 |
▶ | RETVAL = mqdes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = mqdes; |
14 |
2 |
16 |
|
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |
| 67 |
|
| |
| 68 |
|
| int |
| 69 |
|
| mq_close(mqdes) |
| 70 |
|
| mqd_t mqdes |
| 71 |
|
| CODE: |
| 72 |
16 |
▶ | if (mq_close(mqdes) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_close(mqdes) == -1) { XSRETURN_UNDEF; } |
0 |
16 |
16 |
|
| 73 |
16 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
14 |
2 |
16 |
|
| 74 |
|
| OUTPUT: |
| 75 |
|
| RETVAL |
| 76 |
|
| |
| 77 |
|
| int |
| 78 |
|
| mq_unlink(name) |
| 79 |
|
| char* name |
| 80 |
|
| CODE: |
| 81 |
22 |
▶ | if (mq_unlink(name) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_unlink(name) == -1) { XSRETURN_UNDEF; } |
10 |
12 |
22 |
|
| 82 |
12 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
9 |
3 |
12 |
|
| 83 |
|
| OUTPUT: |
| 84 |
|
| RETVAL |
| 85 |
|
| |
| 86 |
|
| SV* |
| 87 |
|
| mq_attr(mqdes, new_attr=NULL) |
| 88 |
|
| mqd_t mqdes |
| 89 |
|
| SV* new_attr; |
| 90 |
|
| PREINIT: |
| 91 |
|
| struct mq_attr old_mqa; |
| 92 |
|
| struct mq_attr* new_mqa_ptr; |
| 93 |
|
| STRLEN new_mqa_len; |
| 94 |
|
| CODE: |
| 95 |
16 |
▶ | if (new_attr == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (new_attr == NULL) |
16 |
0 |
16 |
|
| 96 |
|
| { |
| 97 |
16 |
▶ | if (mq_getattr(mqdes, &old_mqa) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_getattr(mqdes, &old_mqa) == -1) { XSRETURN_UNDEF; } |
0 |
16 |
16 |
|
| 98 |
|
| } |
| 99 |
|
| else |
| 100 |
|
| { |
| 101 |
0 |
| new_mqa_ptr = (struct mq_attr*) SvPV(new_attr, new_mqa_len); |
| 102 |
|
| /* check new_mqa_len ? */ |
| 103 |
0 |
▶ | if (mq_setattr(mqdes, new_mqa_ptr, &old_mqa) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_setattr(mqdes, new_mqa_ptr, &old_mqa) == -1) { XSRETURN_UNDEF; } |
0 |
0 |
0 |
|
| 104 |
|
| } |
| 105 |
16 |
| RETVAL = newSVpvn((char*)&old_mqa, sizeof(old_mqa)); |
| 106 |
|
| OUTPUT: |
| 107 |
|
| RETVAL |
| 108 |
|
| |
| 109 |
|
| int |
| 110 |
|
| mq_send(mqdes, msg, msg_prio) |
| 111 |
|
| mqd_t mqdes |
| 112 |
|
| SV* msg |
| 113 |
|
| unsigned int msg_prio |
| 114 |
|
| PREINIT: |
| 115 |
|
| char* msg_ptr; |
| 116 |
|
| STRLEN msg_len; |
| 117 |
|
| CODE: |
| 118 |
44 |
| msg_ptr = SvPV(msg, msg_len); |
| 119 |
44 |
▶ | if (mq_send(mqdes, msg_ptr, msg_len, msg_prio) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_send(mqdes, msg_ptr, msg_len, msg_prio) == -1) { XSRETURN_UNDEF; } |
0 |
44 |
44 |
|
| 120 |
44 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
43 |
1 |
44 |
|
| 121 |
|
| OUTPUT: |
| 122 |
|
| RETVAL |
| 123 |
|
| |
| 124 |
|
| void |
| 125 |
|
| mq_receive(mqdes, msg_max_len) |
| 126 |
|
| mqd_t mqdes |
| 127 |
|
| size_t msg_max_len |
| 128 |
|
| PREINIT: |
| 129 |
|
| char* msg_ptr; |
| 130 |
|
| ssize_t msg_len; |
| 131 |
|
| unsigned int msg_prio; |
| 132 |
|
| PPCODE: |
| 133 |
44 |
▶ | if ((msg_ptr = malloc(msg_max_len)) == NULL) { XSRETURN_EMPTY; } |
Branch: 1 branch
| Branch | True | False | Total |
| if ((msg_ptr = malloc(msg_max_len)) == NULL) { XSRETURN_EMPTY; } |
0 |
44 |
44 |
|
| 134 |
44 |
| msg_len = mq_receive(mqdes, msg_ptr, msg_max_len, &msg_prio); |
| 135 |
44 |
▶ | if (msg_len == -1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (msg_len == -1) |
0 |
44 |
44 |
|
| 136 |
|
| { |
| 137 |
0 |
| free(msg_ptr); |
| 138 |
0 |
| XSRETURN_EMPTY; |
| 139 |
|
| } |
| 140 |
44 |
▶ | XPUSHs(sv_2mortal(newSVpvn(msg_ptr, msg_len))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(msg_ptr, msg_len))); |
0 |
44 |
44 |
|
| 141 |
44 |
▶ | XPUSHs(sv_2mortal(newSVuv(msg_prio))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVuv(msg_prio))); |
0 |
44 |
44 |
|
| 142 |
44 |
| free(msg_ptr); |
| 143 |
|
| |
| 144 |
|
| int |
| 145 |
|
| mq_notify(mqdes, ...) |
| 146 |
|
| mqd_t mqdes |
| 147 |
|
| PREINIT: |
| 148 |
|
| struct sigevent sigev; |
| 149 |
0 |
▶ | struct sigevent* sigevp = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| struct sigevent* sigevp = NULL; |
0 |
0 |
0 |
|
| 150 |
|
| CODE: |
| 151 |
0 |
▶ | if (items > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) |
0 |
0 |
0 |
|
| 152 |
|
| { |
| 153 |
0 |
| sigev.sigev_notify = SIGEV_SIGNAL; |
| 154 |
0 |
| sigev.sigev_signo = SvIV(ST(1)); |
| 155 |
0 |
| sigev.sigev_value.sival_int = 0; |
| 156 |
0 |
| sigevp = &sigev; |
| 157 |
|
| } |
| 158 |
0 |
▶ | if (mq_notify(mqdes, sigevp) == -1) { XSRETURN_UNDEF; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (mq_notify(mqdes, sigevp) == -1) { XSRETURN_UNDEF; } |
0 |
0 |
0 |
|
| 159 |
0 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
0 |
0 |
0 |
|
| 160 |
|
| OUTPUT: |
| 161 |
|
| RETVAL |
| 162 |
|
| |
| 163 |
|
| |
| 164 |
|
| SV* |
| 165 |
|
| mq_attr_pack(mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs) |
| 166 |
|
| long mq_flags |
| 167 |
|
| long mq_maxmsg |
| 168 |
|
| long mq_msgsize |
| 169 |
|
| long mq_curmsgs |
| 170 |
|
| PREINIT: |
| 171 |
|
| struct mq_attr mqa; |
| 172 |
|
| CODE: |
| 173 |
14 |
| mqa.mq_flags = mq_flags; |
| 174 |
14 |
| mqa.mq_maxmsg = mq_maxmsg; |
| 175 |
14 |
| mqa.mq_msgsize = mq_msgsize; |
| 176 |
14 |
| mqa.mq_curmsgs = mq_curmsgs; |
| 177 |
14 |
| RETVAL = newSVpvn((char*)&mqa, sizeof(mqa)); |
| 178 |
|
| OUTPUT: |
| 179 |
|
| RETVAL |
| 180 |
|
| |
| 181 |
|
| void |
| 182 |
|
| mq_attr_unpack(mqa) |
| 183 |
|
| SV* mqa |
| 184 |
|
| PREINIT: |
| 185 |
|
| struct mq_attr* mqa_ptr; |
| 186 |
|
| STRLEN mqa_len; |
| 187 |
|
| PPCODE: |
| 188 |
16 |
| mqa_ptr = (struct mq_attr*) SvPV(mqa, mqa_len); |
| 189 |
|
| /* check mqa_len ? */ |
| 190 |
16 |
▶ | XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_flags))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_flags))); |
0 |
16 |
16 |
|
| 191 |
16 |
▶ | XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_maxmsg))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_maxmsg))); |
0 |
16 |
16 |
|
| 192 |
16 |
▶ | XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_msgsize))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_msgsize))); |
0 |
16 |
16 |
|
| 193 |
16 |
▶ | XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_curmsgs))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(mqa_ptr->mq_curmsgs))); |
0 |
16 |
16 |
|