| 1 |
|
| /* Hyperman::Event::Epoll - the Linux readiness backend. Implements the |
| 2 |
|
| * hm_backend interface from hyperman.h: io via epoll_ctl (per-fd combined |
| 3 |
|
| * mask, oneshot emulated by clearing after delivery), timers via |
| 4 |
|
| * timerfd_create, signals via signalfd (the signals are blocked and read |
| 5 |
|
| * as data). */ |
| 6 |
|
| |
| 7 |
|
| #include "hyperman.h" |
| 8 |
|
| |
| 9 |
|
| #ifdef __linux__ |
| 10 |
|
| #define HM_HAVE_EPOLL 1 |
| 11 |
|
| #endif |
| 12 |
|
| |
| 13 |
|
| #ifdef HM_HAVE_EPOLL |
| 14 |
|
| |
| 15 |
|
| #include <sys/epoll.h> |
| 16 |
|
| #include <sys/timerfd.h> |
| 17 |
|
| #include <sys/signalfd.h> |
| 18 |
|
| #include <signal.h> |
| 19 |
|
| #include <string.h> |
| 20 |
|
| #include <stdlib.h> |
| 21 |
|
| #include <unistd.h> |
| 22 |
|
| #include <errno.h> |
| 23 |
|
| |
| 24 |
|
| #define EP_NONE 0 |
| 25 |
|
| #define EP_IO 1 |
| 26 |
|
| #define EP_TIMER 2 |
| 27 |
|
| #define EP_SIGNAL 3 |
| 28 |
|
| |
| 29 |
|
| typedef struct { |
| 30 |
|
| int ep; /* epoll fd */ |
| 31 |
|
| int sfd; /* signalfd, -1 until first signal */ |
| 32 |
|
| sigset_t sigs; |
| 33 |
|
| unsigned char kind[HM_MAXFD]; /* EP_* per registered fd */ |
| 34 |
|
| unsigned char mask[HM_MAXFD]; /* current HM_EV_ bits (io fds) */ |
| 35 |
|
| unsigned char once[HM_MAXFD]; /* oneshot HM_EV_ bits (io fds) */ |
| 36 |
|
| void *tudata[HM_MAXFD]; /* timerfd -> watcher udata */ |
| 37 |
|
| unsigned char toneshot[HM_MAXFD]; |
| 38 |
|
| } hm_ep_state; |
| 39 |
|
| |
| 40 |
55377 |
| static int ep_ctl_io(hm_ep_state *st, int fd) { |
| 41 |
|
| struct epoll_event ev; |
| 42 |
|
| int op; |
| 43 |
55377 |
| memset(&ev, 0, sizeof(ev)); |
| 44 |
55377 |
| ev.data.fd = fd; |
| 45 |
55377 |
▶ | if (st->mask[fd] & HM_EV_READ) ev.events |= EPOLLIN; |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->mask[fd] & HM_EV_READ) ev.events |= EPOLLIN; |
27756 |
27621 |
55377 |
|
| 46 |
55377 |
▶ | if (st->mask[fd] & HM_EV_WRITE) ev.events |= EPOLLOUT; |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->mask[fd] & HM_EV_WRITE) ev.events |= EPOLLOUT; |
9 |
55368 |
55377 |
|
| 47 |
55377 |
▶ | if (st->mask[fd] == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->mask[fd] == 0) { |
27620 |
27757 |
55377 |
|
| 48 |
27620 |
| st->kind[fd] = EP_NONE; |
| 49 |
27620 |
| return epoll_ctl(st->ep, EPOLL_CTL_DEL, fd, NULL); |
| 50 |
|
| } |
| 51 |
27757 |
▶ | op = (st->kind[fd] == EP_IO) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; |
Branch: 1 branch
| Branch | True | False | Total |
| op = (st->kind[fd] == EP_IO) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; |
17 |
27740 |
27757 |
|
| 52 |
27757 |
| st->kind[fd] = EP_IO; |
| 53 |
27757 |
| return epoll_ctl(st->ep, op, fd, &ev); |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
27750 |
| static int ep_add_io(hm_backend *be, int fd, int mask, int oneshot) { |
| 57 |
27750 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 58 |
|
| /* |
| 59 |
|
| # uncoverable condition left count:1 |
| 60 |
|
| # uncoverable branch true |
| 61 |
|
| # uncoverable condition left count:2 */ |
| 62 |
27750 |
▶ | if (fd < 0 || fd >= HM_MAXFD) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (fd < 0 || fd >= HM_MAXFD) return -1; |
27750 |
0 |
27750 |
| if (fd < 0 || fd >= HM_MAXFD) return -1; |
0 |
27750 |
27750 |
|
| 63 |
27750 |
| st->mask[fd] |= (unsigned char)mask; |
| 64 |
27750 |
▶ | if (oneshot) st->once[fd] |= (unsigned char)mask; |
Branch: 1 branch
| Branch | True | False | Total |
| if (oneshot) st->once[fd] |= (unsigned char)mask; |
7 |
27743 |
27750 |
|
| 65 |
27743 |
| else st->once[fd] &= (unsigned char)~mask; |
| 66 |
27750 |
| return ep_ctl_io(st, fd); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
|
| /* |
| 70 |
|
| # uncoverable statement |
| 71 |
|
| # uncoverable subroutine */ |
| 72 |
0 |
| static int ep_modify_io(hm_backend *be, int fd, int mask, int oneshot) { |
| 73 |
0 |
| return ep_add_io(be, fd, mask, oneshot); /* # uncoverable statement */ |
| 74 |
|
| } |
| 75 |
|
| |
| 76 |
27628 |
| static int ep_remove_io(hm_backend *be, int fd, int mask) { |
| 77 |
27628 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 78 |
|
| /* |
| 79 |
|
| # uncoverable condition left count:1 |
| 80 |
|
| # uncoverable branch true |
| 81 |
|
| # uncoverable condition left count:2 */ |
| 82 |
27628 |
▶ | if (fd < 0 || fd >= HM_MAXFD) return -1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (fd < 0 || fd >= HM_MAXFD) return -1; |
27628 |
0 |
27628 |
| if (fd < 0 || fd >= HM_MAXFD) return -1; |
0 |
27628 |
27628 |
|
| 83 |
27628 |
▶ | if (st->kind[fd] != EP_IO) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->kind[fd] != EP_IO) return 0; |
1 |
27627 |
27628 |
|
| 84 |
27627 |
| st->mask[fd] &= (unsigned char)~mask; |
| 85 |
27627 |
| st->once[fd] &= (unsigned char)~mask; |
| 86 |
27627 |
| return ep_ctl_io(st, fd); |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
29105 |
| static int ep_add_timer(hm_backend *be, double secs, int oneshot, void *udata) { |
| 90 |
29105 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 91 |
|
| struct itimerspec its; |
| 92 |
|
| struct epoll_event ev; |
| 93 |
29105 |
| int tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); |
| 94 |
29105 |
▶ | if (tfd < 0 || tfd >= HM_MAXFD) { if (tfd >= 0) close(tfd); return -1; } /* # uncoverable condition left count:2 */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (tfd < 0 || tfd >= HM_MAXFD) { if (tfd >= 0) close(tfd); return -1; } /* # uncoverable condition left count:2 */ |
2595 |
26510 |
29105 |
| if (tfd < 0 || tfd >= HM_MAXFD) { if (tfd >= 0) close(tfd); return -1; } /* # uncoverable condition left count:2 */ |
0 |
2595 |
2595 |
| if (tfd < 0 || tfd >= HM_MAXFD) { if (tfd >= 0) close(tfd); return -1; } /* # uncoverable condition left count:2 */ |
0 |
26510 |
26510 |
|
| 95 |
2595 |
| memset(&its, 0, sizeof(its)); |
| 96 |
2595 |
| its.it_value.tv_sec = (time_t)secs; |
| 97 |
2595 |
| its.it_value.tv_nsec = (long)((secs - (double)its.it_value.tv_sec) * 1e9); |
| 98 |
2595 |
▶ | if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0) |
2212 |
383 |
2595 |
| if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0) |
2039 |
173 |
2212 |
|
| 99 |
2039 |
| its.it_value.tv_nsec = 1; |
| 100 |
2595 |
▶ | if (!oneshot) its.it_interval = its.it_value; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!oneshot) its.it_interval = its.it_value; |
132 |
2463 |
2595 |
|
| 101 |
|
| /* |
| 102 |
|
| # uncoverable branch true |
| 103 |
|
| # uncoverable condition left count:1 */ |
| 104 |
2595 |
▶ | if (timerfd_settime(tfd, 0, &its, NULL) < 0) { close(tfd); return -1; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (timerfd_settime(tfd, 0, &its, NULL) < 0) { close(tfd); return -1; } |
0 |
2595 |
2595 |
|
| 105 |
2595 |
| st->kind[tfd] = EP_TIMER; |
| 106 |
2595 |
| st->tudata[tfd] = udata; |
| 107 |
2595 |
▶ | st->toneshot[tfd] = (unsigned char)(oneshot ? 1 : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| st->toneshot[tfd] = (unsigned char)(oneshot ? 1 : 0); |
2463 |
132 |
2595 |
|
| 108 |
2595 |
| memset(&ev, 0, sizeof(ev)); |
| 109 |
2595 |
| ev.events = EPOLLIN; |
| 110 |
2595 |
| ev.data.fd = tfd; |
| 111 |
2595 |
| return epoll_ctl(st->ep, EPOLL_CTL_ADD, tfd, &ev); |
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
11 |
| static int ep_del_timer(hm_backend *be, void *udata) { |
| 115 |
11 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 116 |
|
| int fd; |
| 117 |
655381 |
▶ | for (fd = 0; fd < HM_MAXFD; fd++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (fd = 0; fd < HM_MAXFD; fd++) { |
655371 |
10 |
655381 |
|
| 118 |
655371 |
▶ | if (st->kind[fd] == EP_TIMER && st->tudata[fd] == udata) { /* # uncoverable condition right count:2 */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (st->kind[fd] == EP_TIMER && st->tudata[fd] == udata) { /* # uncoverable condition right count:2 */ |
1 |
655370 |
655371 |
| if (st->kind[fd] == EP_TIMER && st->tudata[fd] == udata) { /* # uncoverable condition right count:2 */ |
1 |
0 |
1 |
|
| 119 |
1 |
| epoll_ctl(st->ep, EPOLL_CTL_DEL, fd, NULL); |
| 120 |
1 |
| close(fd); |
| 121 |
1 |
| st->kind[fd] = EP_NONE; |
| 122 |
1 |
| st->tudata[fd] = NULL; |
| 123 |
1 |
| return 0; |
| 124 |
|
| } |
| 125 |
|
| } |
| 126 |
10 |
| return -1; |
| 127 |
|
| } |
| 128 |
|
| |
| 129 |
396 |
| static int ep_add_signal(hm_backend *be, int signo) { |
| 130 |
396 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 131 |
396 |
| sigaddset(&st->sigs, signo); |
| 132 |
|
| /* |
| 133 |
|
| # uncoverable branch true |
| 134 |
|
| # uncoverable condition left count:1 */ |
| 135 |
396 |
▶ | if (sigprocmask(SIG_BLOCK, &st->sigs, NULL) < 0) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (sigprocmask(SIG_BLOCK, &st->sigs, NULL) < 0) return -1; |
0 |
396 |
396 |
|
| 136 |
|
| { |
| 137 |
396 |
| int sfd = signalfd(st->sfd, &st->sigs, SFD_NONBLOCK | SFD_CLOEXEC); |
| 138 |
|
| /* |
| 139 |
|
| # uncoverable branch true |
| 140 |
|
| # uncoverable condition left count:1 */ |
| 141 |
396 |
▶ | if (sfd < 0) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (sfd < 0) return -1; |
0 |
396 |
396 |
|
| 142 |
396 |
▶ | if (st->sfd < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->sfd < 0) { |
132 |
264 |
396 |
|
| 143 |
|
| struct epoll_event ev; |
| 144 |
132 |
| st->sfd = sfd; |
| 145 |
132 |
| st->kind[sfd] = EP_SIGNAL; |
| 146 |
132 |
| memset(&ev, 0, sizeof(ev)); |
| 147 |
132 |
| ev.events = EPOLLIN; |
| 148 |
132 |
| ev.data.fd = sfd; |
| 149 |
132 |
| return epoll_ctl(st->ep, EPOLL_CTL_ADD, sfd, &ev); |
| 150 |
|
| } |
| 151 |
|
| } |
| 152 |
264 |
| return 0; |
| 153 |
|
| } |
| 154 |
|
| |
| 155 |
31206 |
| static int ep_wait(hm_backend *be, hm_event *out, int max, double timeout) { |
| 156 |
31206 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 157 |
|
| struct epoll_event evs[HM_MAXEV]; |
| 158 |
31206 |
▶ | int tmo_ms = timeout < 0 ? -1 : (int)(timeout * 1000); |
Branch: 1 branch
| Branch | True | False | Total |
| int tmo_ms = timeout < 0 ? -1 : (int)(timeout * 1000); |
31204 |
2 |
31206 |
|
| 159 |
31206 |
| int n, i, nev = 0; |
| 160 |
|
| /* |
| 161 |
|
| # uncoverable branch true |
| 162 |
|
| # uncoverable condition left count:1 */ |
| 163 |
31206 |
▶ | if (max > HM_MAXEV) max = HM_MAXEV; |
Branch: 1 branch
| Branch | True | False | Total |
| if (max > HM_MAXEV) max = HM_MAXEV; |
0 |
31206 |
31206 |
|
| 164 |
31206 |
| n = epoll_wait(st->ep, evs, max, tmo_ms); |
| 165 |
31206 |
▶ | if (n < 0) return (errno == EINTR) ? 0 : -1; /* # uncoverable condition right count:2 */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (n < 0) return (errno == EINTR) ? 0 : -1; /* # uncoverable condition right count:2 */ |
1 |
31205 |
31206 |
| if (n < 0) return (errno == EINTR) ? 0 : -1; /* # uncoverable condition right count:2 */ |
1 |
0 |
1 |
|
| 166 |
62504 |
▶ | for (i = 0; i < n && nev < max; i++) { /* # uncoverable condition right count:2 */ |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < n && nev < max; i++) { /* # uncoverable condition right count:2 */ |
31299 |
31205 |
62504 |
| for (i = 0; i < n && nev < max; i++) { /* # uncoverable condition right count:2 */ |
31299 |
0 |
31299 |
|
| 167 |
31299 |
| int fd = evs[i].data.fd; |
| 168 |
31299 |
| switch (st->kind[fd]) { |
| 169 |
2338 |
| case EP_TIMER: { |
| 170 |
|
| unsigned long long exp; |
| 171 |
2338 |
| ssize_t r = read(fd, &exp, sizeof(exp)); |
| 172 |
|
| (void)r; |
| 173 |
2338 |
| out[nev].kind = HM_EV_TIMER; |
| 174 |
2338 |
| out[nev].fd = -1; |
| 175 |
2338 |
| out[nev].udata = st->tudata[fd]; |
| 176 |
2338 |
| nev++; |
| 177 |
2338 |
▶ | if (st->toneshot[fd]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->toneshot[fd]) { |
2323 |
15 |
2338 |
|
| 178 |
2323 |
| epoll_ctl(st->ep, EPOLL_CTL_DEL, fd, NULL); |
| 179 |
2323 |
| close(fd); |
| 180 |
2323 |
| st->kind[fd] = EP_NONE; |
| 181 |
2323 |
| st->tudata[fd] = NULL; |
| 182 |
|
| } |
| 183 |
2338 |
| break; |
| 184 |
|
| } |
| 185 |
127 |
| case EP_SIGNAL: { |
| 186 |
|
| struct signalfd_siginfo si; |
| 187 |
127 |
| while (nev < max |
| 188 |
254 |
▶ | && read(fd, &si, sizeof(si)) == (ssize_t)sizeof(si)) { /* # uncoverable condition right count:1 */ |
Branch: 2 branches
| Branch | True | False | Total |
| && read(fd, &si, sizeof(si)) == (ssize_t)sizeof(si)) { /* # uncoverable condition right count:1 */ |
254 |
0 |
254 |
| && read(fd, &si, sizeof(si)) == (ssize_t)sizeof(si)) { /* # uncoverable condition right count:1 */ |
127 |
127 |
254 |
|
| 189 |
127 |
| out[nev].kind = HM_EV_SIGNAL; |
| 190 |
127 |
| out[nev].fd = (int)si.ssi_signo; |
| 191 |
127 |
| out[nev].udata = NULL; |
| 192 |
127 |
| nev++; |
| 193 |
|
| } |
| 194 |
127 |
| break; |
| 195 |
|
| } |
| 196 |
28834 |
| default: { |
| 197 |
28834 |
| unsigned ev = evs[i].events; |
| 198 |
28834 |
| int got = 0; |
| 199 |
28834 |
▶ | if (ev & (EPOLLIN | EPOLLHUP | EPOLLERR)) got |= HM_EV_READ; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ev & (EPOLLIN | EPOLLHUP | EPOLLERR)) got |= HM_EV_READ; |
28817 |
17 |
28834 |
|
| 200 |
28834 |
▶ | if (ev & (EPOLLOUT | EPOLLHUP | EPOLLERR)) got |= HM_EV_WRITE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ev & (EPOLLOUT | EPOLLHUP | EPOLLERR)) got |= HM_EV_WRITE; |
17 |
28817 |
28834 |
|
| 201 |
28834 |
| got &= st->mask[fd]; |
| 202 |
|
| /* |
| 203 |
|
| # uncoverable branch true |
| 204 |
|
| # uncoverable condition left count:1 */ |
| 205 |
28834 |
▶ | if (!got) got = st->mask[fd]; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!got) got = st->mask[fd]; |
0 |
28834 |
28834 |
|
| 206 |
28834 |
▶ | if (got & HM_EV_READ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (got & HM_EV_READ) { |
28817 |
17 |
28834 |
|
| 207 |
28817 |
| out[nev].kind = HM_EV_READ; |
| 208 |
28817 |
| out[nev].fd = fd; |
| 209 |
28817 |
| out[nev].udata = NULL; |
| 210 |
28817 |
| nev++; |
| 211 |
|
| } |
| 212 |
28834 |
▶ | if ((got & HM_EV_WRITE) && nev < max) { /* # uncoverable condition right count:2 */ |
Branch: 2 branches
| Branch | True | False | Total |
| if ((got & HM_EV_WRITE) && nev < max) { /* # uncoverable condition right count:2 */ |
17 |
28817 |
28834 |
| if ((got & HM_EV_WRITE) && nev < max) { /* # uncoverable condition right count:2 */ |
17 |
0 |
17 |
|
| 213 |
17 |
| out[nev].kind = HM_EV_WRITE; |
| 214 |
17 |
| out[nev].fd = fd; |
| 215 |
17 |
| out[nev].udata = NULL; |
| 216 |
17 |
| nev++; |
| 217 |
|
| } |
| 218 |
28834 |
▶ | if (st->once[fd] & got) |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->once[fd] & got) |
5 |
28829 |
28834 |
|
| 219 |
5 |
| ep_remove_io(be, fd, st->once[fd] & got); |
| 220 |
28834 |
| break; |
| 221 |
|
| } |
| 222 |
|
| } |
| 223 |
|
| } |
| 224 |
31205 |
| return nev; |
| 225 |
|
| } |
| 226 |
|
| |
| 227 |
154 |
| static void ep_destroy(hm_backend *be) { |
| 228 |
154 |
| hm_ep_state *st = (hm_ep_state *)be->state; |
| 229 |
|
| /* |
| 230 |
|
| # uncoverable branch false |
| 231 |
|
| # uncoverable condition right count:1 */ |
| 232 |
154 |
▶ | if (st) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (st) { |
154 |
0 |
154 |
|
| 233 |
|
| /* be->foreign: inherited across a fork - these descriptors are the |
| 234 |
|
| * parent's, and closing our duplicates only frees numbers the child |
| 235 |
|
| * has already reused */ |
| 236 |
154 |
▶ | if (!be->foreign) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!be->foreign) { |
151 |
3 |
154 |
|
| 237 |
|
| int fd; |
| 238 |
9896087 |
▶ | for (fd = 0; fd < HM_MAXFD; fd++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (fd = 0; fd < HM_MAXFD; fd++) |
9895936 |
151 |
9896087 |
|
| 239 |
9895936 |
▶ | if (st->kind[fd] == EP_TIMER) close(fd); |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->kind[fd] == EP_TIMER) close(fd); |
270 |
9895666 |
9895936 |
|
| 240 |
151 |
▶ | if (st->sfd >= 0) close(st->sfd); |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->sfd >= 0) close(st->sfd); |
132 |
19 |
151 |
|
| 241 |
|
| /* |
| 242 |
|
| # uncoverable branch false |
| 243 |
|
| # uncoverable condition right count:1 */ |
| 244 |
151 |
▶ | if (st->ep >= 0) close(st->ep); |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->ep >= 0) close(st->ep); |
151 |
0 |
151 |
|
| 245 |
|
| } |
| 246 |
154 |
| free(st); |
| 247 |
|
| } |
| 248 |
154 |
| free(be); |
| 249 |
154 |
| } |
| 250 |
|
| |
| 251 |
156 |
| hm_backend *hm_backend_epoll_new(void) { |
| 252 |
156 |
| hm_backend *be = (hm_backend *)hm_xcalloc(1, sizeof(hm_backend)); |
| 253 |
156 |
| hm_ep_state *st = (hm_ep_state *)hm_xcalloc(1, sizeof(hm_ep_state)); |
| 254 |
|
| /* |
| 255 |
|
| # uncoverable branch true |
| 256 |
|
| # uncoverable condition left count:1 |
| 257 |
|
| # uncoverable condition left count:2 */ |
| 258 |
156 |
▶ | if (!be || !st) { free(be); free(st); return NULL; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (!be || !st) { free(be); free(st); return NULL; } |
156 |
0 |
156 |
| if (!be || !st) { free(be); free(st); return NULL; } |
0 |
156 |
156 |
|
| 259 |
156 |
| st->ep = epoll_create1(EPOLL_CLOEXEC); |
| 260 |
|
| /* |
| 261 |
|
| # uncoverable branch true |
| 262 |
|
| # uncoverable condition left count:1 */ |
| 263 |
156 |
▶ | if (st->ep < 0) { free(be); free(st); return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (st->ep < 0) { free(be); free(st); return NULL; } |
0 |
156 |
156 |
|
| 264 |
156 |
| st->sfd = -1; |
| 265 |
156 |
| sigemptyset(&st->sigs); |
| 266 |
156 |
| be->name = "epoll"; |
| 267 |
156 |
| be->state = st; |
| 268 |
156 |
| be->add_io = ep_add_io; |
| 269 |
156 |
| be->modify_io = ep_modify_io; |
| 270 |
156 |
| be->remove_io = ep_remove_io; |
| 271 |
156 |
| be->add_timer = ep_add_timer; |
| 272 |
156 |
| be->del_timer = ep_del_timer; |
| 273 |
156 |
| be->add_signal = ep_add_signal; |
| 274 |
156 |
| be->wait = ep_wait; |
| 275 |
156 |
| be->destroy = ep_destroy; |
| 276 |
156 |
| return be; |
| 277 |
|
| } |
| 278 |
|
| |
| 279 |
5 |
| int hm_backend_epoll_available(void) { return 1; } |
| 280 |
|
| |
| 281 |
|
| #else /* !HM_HAVE_EPOLL */ |
| 282 |
|
| |
| 283 |
|
| hm_backend *hm_backend_epoll_new(void) { return 0; } |
| 284 |
|
| int hm_backend_epoll_available(void) { return 0; } |
| 285 |
|
| |
| 286 |
|
| #endif |