mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-14 10:09:31 +00:00
Simplify epoll handling slightly
No need to allocate the epoll events array since it's static in size anyway. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
9b5be13e62
commit
85da186489
2 files changed
+4
-13
No files matched your search
@@ -96,13 +96,7 @@ uev_t *uev_ctx_create(void)
|
||||
return NULL;
|
||||
|
||||
ctx = (uev_t *)calloc(1, sizeof(*ctx));
|
||||
if (!ctx)
|
||||
goto exit;
|
||||
|
||||
ctx->events = (struct epoll_event *)calloc(UEV_MAX_EVENTS, sizeof(struct epoll_event));
|
||||
if (!ctx->events) {
|
||||
free(ctx);
|
||||
exit:
|
||||
if (!ctx) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -129,7 +123,6 @@ void uev_ctx_delete(uev_t *ctx)
|
||||
}
|
||||
|
||||
close(ctx->efd);
|
||||
free(ctx->events);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@@ -160,8 +153,9 @@ int uev_run(uev_t *ctx)
|
||||
|
||||
while (ctx->running) {
|
||||
int i, nfds;
|
||||
struct epoll_event events[UEV_MAX_EVENTS];
|
||||
|
||||
while ((nfds = epoll_wait(ctx->efd, ctx->events, UEV_MAX_EVENTS, -1)) < 0) {
|
||||
while ((nfds = epoll_wait(ctx->efd, events, UEV_MAX_EVENTS, -1)) < 0) {
|
||||
if (EINTR == errno)
|
||||
continue; /* Signalled, try again */
|
||||
|
||||
@@ -171,7 +165,7 @@ int uev_run(uev_t *ctx)
|
||||
}
|
||||
|
||||
for (i = 0; i < nfds; i++) {
|
||||
w = (uev_io_t *)ctx->events[i].data.ptr;
|
||||
w = (uev_io_t *)events[i].data.ptr;
|
||||
|
||||
if (w->handler)
|
||||
w->handler((struct uev *)ctx, w, w->data);
|
||||
|
||||
Reference in new issue
Block a user