Epoll.xs

filter: Statementstmt 82.5% 33 / 40 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.3% 45 / 56 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« const-c.inc ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include "ppport.h"
6  
7 #include <sys/epoll.h>
8  
9 #include "const-c.inc"
10  
11 MODULE = IO::Epoll PACKAGE = IO::Epoll
12  
13 INCLUDE: const-xs.inc
14  
15 int
16 epoll_create(size)
17 int size
18  
19 int
20 epoll_ctl(epfd,op,fd,events)
21 int epfd
22 int op
23 int fd
24 unsigned long events
25 CODE:
26 struct epoll_event event;
27 int ret;
28 9 event.events = events;
29 9 event.data.fd = fd;
30  
31 9 RETVAL = epoll_ctl(epfd, op, fd, &event);
32 OUTPUT:
33 RETVAL
34  
35 SV *
36 epoll_wait(epfd,maxevents,timeout)
37 int epfd
38 int maxevents
39 int timeout
40 CODE:
41 struct epoll_event *events;
42 int ret, i;
43  
44 1 events = (struct epoll_event *)malloc(maxevents * sizeof(struct epoll_event));
45 1 ▶ if (!events) {
Branch: 1 branch
BranchTrueFalseTotal
if (!events) { 0 1 1
46 0 errno = ENOMEM;
47 0 XSRETURN_UNDEF;
48 }
49 1 ret = epoll_wait(epfd, events, maxevents, timeout);
50 1 ▶ if (ret < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret < 0) { 0 1 1
51 0 free(events);
52 0 XSRETURN_UNDEF;
53 } else {
54 1 AV *results = (AV*)sv_2mortal((SV*)newAV());
55 2 ▶ for (i = 0; i < ret; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ret; i++) { 1 1 2
56 1 AV *ev = (AV*)sv_2mortal((SV*)newAV());
57 1 av_push(ev, newSVnv(events[i].data.fd));
58 1 av_push(ev, newSVnv(events[i].events));
59 1 av_push(results, newRV((SV*) ev));
60 }
61 1 RETVAL = newRV((SV *)results);
62 1 free(events);
63 }
64 OUTPUT:
65 RETVAL
66  
67 SV *
68 epoll_pwait(epfd,maxevents,timeout,sigmask)
69 int epfd
70 int maxevents
71 int timeout
72 SV *sigmask
73 CODE:
74 struct epoll_event *events;
75 sigset_t *sigmask_real;
76 int ret, i;
77  
78 6 ▶ if(SvOK(sigmask)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvOK(sigmask)) { 2 4 6
79 2 ▶ if(!sv_derived_from(sigmask, "POSIX::SigSet"))
Branch: 1 branch
BranchTrueFalseTotal
if(!sv_derived_from(sigmask, "POSIX::SigSet")) 0 2 2
80 0 Perl_croak(aTHX_ "epoll_pwait: sigmask is not of type POSIX::SigSet");
81 #if PERL_VERSION > 15 || PERL_VERSION == 15 && PERL_SUBVERSION > 2
82 4 sigmask_real = (sigset_t *) SvPV_nolen(SvRV(sigmask));
83 #else
84 /* This code borrowed from POSIX.xs */
85 IV tmp = SvIV((SV*)SvRV(sigmask));
86 sigmask_real = INT2PTR(sigset_t*, tmp);
87 #endif
88 }
89 else {
90 4 sigmask_real = NULL;
91 }
92  
93 6 events = (struct epoll_event *)malloc(maxevents * sizeof(struct epoll_event));
94 6 ▶ if (!events) {
Branch: 1 branch
BranchTrueFalseTotal
if (!events) { 0 6 6
95 0 errno = ENOMEM;
96 0 XSRETURN_UNDEF;
97 }
98 6 ret = epoll_pwait(epfd, events, maxevents, timeout, sigmask_real);
99 6 ▶ if (ret < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret < 0) { 1 5 6
100 1 free(events);
101 1 XSRETURN_UNDEF;
102 } else {
103 5 AV *results = (AV*)sv_2mortal((SV*)newAV());
104 6 ▶ for (i = 0; i < ret; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ret; i++) { 1 5 6
105 1 AV *ev = (AV*)sv_2mortal((SV*)newAV());
106 1 av_push(ev, newSVnv(events[i].data.fd));
107 1 av_push(ev, newSVnv(events[i].events));
108 1 av_push(results, newRV((SV*) ev));
109 }
110 5 RETVAL = newRV((SV *)results);
111 5 free(events);
112 }
113 OUTPUT:
114 RETVAL
« const-c.inc ↑ Summary