mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-20 19:52:16 +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;
|
return NULL;
|
||||||
|
|
||||||
ctx = (uev_t *)calloc(1, sizeof(*ctx));
|
ctx = (uev_t *)calloc(1, sizeof(*ctx));
|
||||||
if (!ctx)
|
if (!ctx) {
|
||||||
goto exit;
|
|
||||||
|
|
||||||
ctx->events = (struct epoll_event *)calloc(UEV_MAX_EVENTS, sizeof(struct epoll_event));
|
|
||||||
if (!ctx->events) {
|
|
||||||
free(ctx);
|
|
||||||
exit:
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -129,7 +123,6 @@ void uev_ctx_delete(uev_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(ctx->efd);
|
close(ctx->efd);
|
||||||
free(ctx->events);
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +153,9 @@ int uev_run(uev_t *ctx)
|
|||||||
|
|
||||||
while (ctx->running) {
|
while (ctx->running) {
|
||||||
int i, nfds;
|
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)
|
if (EINTR == errno)
|
||||||
continue; /* Signalled, try again */
|
continue; /* Signalled, try again */
|
||||||
|
|
||||||
@@ -171,7 +165,7 @@ int uev_run(uev_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nfds; i++) {
|
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)
|
if (w->handler)
|
||||||
w->handler((struct uev *)ctx, w, w->data);
|
w->handler((struct uev *)ctx, w, w->data);
|
||||||
|
|||||||
@@ -65,10 +65,7 @@ typedef struct uev_io {
|
|||||||
/* Main libuev context type */
|
/* Main libuev context type */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
int efd; /* For epoll() */
|
int efd; /* For epoll() */
|
||||||
struct epoll_event *events;
|
|
||||||
|
|
||||||
LIST_HEAD(, uev_io) watchers;
|
LIST_HEAD(, uev_io) watchers;
|
||||||
} uev_t;
|
} uev_t;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user