summaryrefslogtreecommitdiff
path: root/lib/tevent/tevent_standard.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tevent/tevent_standard.c')
-rw-r--r--lib/tevent/tevent_standard.c100
1 files changed, 48 insertions, 52 deletions
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 1c99408b8d..2a292a4c39 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -29,8 +29,7 @@
#include "replace.h"
#include "system/filesys.h"
-#include "system/network.h"
-#include "system/select.h" /* needed for HAVE_EVENTS_EPOLL */
+#include "system/select.h"
#include "tevent.h"
#include "tevent_util.h"
#include "tevent_internal.h"
@@ -64,29 +63,29 @@ struct std_event_context {
};
/* use epoll if it is available */
-#if HAVE_EVENTS_EPOLL
+#if HAVE_EPOLL
/*
called when a epoll call fails, and we should fallback
to using select
*/
static void epoll_fallback_to_select(struct std_event_context *std_ev, const char *reason)
{
- ev_debug(std_ev->ev, EV_DEBUG_FATAL,
- "%s (%s) - falling back to select()\n",
- reason, strerror(errno));
+ tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL,
+ "%s (%s) - falling back to select()\n",
+ reason, strerror(errno));
close(std_ev->epoll_fd);
std_ev->epoll_fd = -1;
talloc_set_destructor(std_ev, NULL);
}
/*
- map from EVENT_FD_* to EPOLLIN/EPOLLOUT
+ map from TEVENT_FD_* to EPOLLIN/EPOLLOUT
*/
static uint32_t epoll_map_flags(uint16_t flags)
{
uint32_t ret = 0;
- if (flags & EVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP);
- if (flags & EVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
+ if (flags & TEVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP);
+ if (flags & TEVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP);
return ret;
}
@@ -130,8 +129,8 @@ static void epoll_check_reopen(struct std_event_context *std_ev)
close(std_ev->epoll_fd);
std_ev->epoll_fd = epoll_create(64);
if (std_ev->epoll_fd == -1) {
- ev_debug(std_ev->ev, EV_DEBUG_FATAL,
- "Failed to recreate epoll handle after fork\n");
+ tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL,
+ "Failed to recreate epoll handle after fork\n");
return;
}
std_ev->pid = getpid();
@@ -166,7 +165,7 @@ static void epoll_add_event(struct std_event_context *std_ev, struct tevent_fd *
fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT;
/* only if we want to read we want to tell the event handler about errors */
- if (fde->flags & EVENT_FD_READ) {
+ if (fde->flags & TEVENT_FD_READ) {
fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
}
}
@@ -209,7 +208,7 @@ static void epoll_mod_event(struct std_event_context *std_ev, struct tevent_fd *
}
/* only if we want to read we want to tell the event handler about errors */
- if (fde->flags & EVENT_FD_READ) {
+ if (fde->flags & TEVENT_FD_READ) {
fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
}
}
@@ -217,8 +216,8 @@ static void epoll_mod_event(struct std_event_context *std_ev, struct tevent_fd *
static void epoll_change_event(struct std_event_context *std_ev, struct tevent_fd *fde)
{
bool got_error = (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR);
- bool want_read = (fde->flags & EVENT_FD_READ);
- bool want_write= (fde->flags & EVENT_FD_WRITE);
+ bool want_read = (fde->flags & TEVENT_FD_READ);
+ bool want_write= (fde->flags & TEVENT_FD_WRITE);
if (std_ev->epoll_fd == -1) return;
@@ -266,14 +265,14 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
}
if (std_ev->ev->num_signal_handlers &&
- common_event_check_signal(std_ev->ev)) {
+ tevent_common_check_signal(std_ev->ev)) {
return 0;
}
ret = epoll_wait(std_ev->epoll_fd, events, MAXEVENTS, timeout);
if (ret == -1 && errno == EINTR && std_ev->ev->num_signal_handlers) {
- if (common_event_check_signal(std_ev->ev)) {
+ if (tevent_common_check_signal(std_ev->ev)) {
return 0;
}
}
@@ -285,7 +284,7 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
if (ret == 0 && tvalp) {
/* we don't care about a possible delay here */
- common_event_loop_timer_delay(std_ev->ev);
+ tevent_common_loop_timer_delay(std_ev->ev);
return 0;
}
@@ -301,7 +300,7 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
if (events[i].events & (EPOLLHUP|EPOLLERR)) {
fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR;
/*
- * if we only wait for EVENT_FD_WRITE, we should not tell the
+ * if we only wait for TEVENT_FD_WRITE, we should not tell the
* event handler about it, and remove the epoll_event,
* as we only report errors when waiting for read events,
* to match the select() behavior
@@ -310,10 +309,10 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
epoll_del_event(std_ev, fde);
continue;
}
- flags |= EVENT_FD_READ;
+ flags |= TEVENT_FD_READ;
}
- if (events[i].events & EPOLLIN) flags |= EVENT_FD_READ;
- if (events[i].events & EPOLLOUT) flags |= EVENT_FD_WRITE;
+ if (events[i].events & EPOLLIN) flags |= TEVENT_FD_READ;
+ if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE;
if (flags) {
fde->handler(std_ev->ev, fde, flags, fde->private_data);
if (destruction_count != std_ev->destruction_count) {
@@ -392,8 +391,8 @@ static int std_event_fd_destructor(struct tevent_fd *fde)
epoll_del_event(std_ev, fde);
- if (fde->flags & EVENT_FD_AUTOCLOSE) {
- close(fde->fd);
+ if (fde->close_fn) {
+ fde->close_fn(ev, fde, fde->fd, fde->private_data);
fde->fd = -1;
}
@@ -405,9 +404,11 @@ static int std_event_fd_destructor(struct tevent_fd *fde)
return NULL on failure (memory allocation error)
*/
static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
- int fd, uint16_t flags,
- event_fd_handler_t handler,
- void *private_data)
+ int fd, uint16_t flags,
+ tevent_fd_handler_t handler,
+ void *private_data,
+ const char *handler_name,
+ const char *location)
{
struct std_event_context *std_ev = talloc_get_type(ev->additional_data,
struct std_event_context);
@@ -422,7 +423,10 @@ static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX
fde->fd = fd;
fde->flags = flags;
fde->handler = handler;
+ fde->close_fn = NULL;
fde->private_data = private_data;
+ fde->handler_name = handler_name;
+ fde->location = location;
fde->additional_flags = 0;
fde->additional_data = NULL;
@@ -438,15 +442,6 @@ static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX
return fde;
}
-
-/*
- return the fd event flags
-*/
-static uint16_t std_event_get_fd_flags(struct tevent_fd *fde)
-{
- return fde->flags;
-}
-
/*
set the fd event flags
*/
@@ -487,16 +482,16 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
/* setup any fd events */
for (fde = std_ev->fd_events; fde; fde = fde->next) {
- if (fde->flags & EVENT_FD_READ) {
+ if (fde->flags & TEVENT_FD_READ) {
FD_SET(fde->fd, &r_fds);
}
- if (fde->flags & EVENT_FD_WRITE) {
+ if (fde->flags & TEVENT_FD_WRITE) {
FD_SET(fde->fd, &w_fds);
}
}
if (std_ev->ev->num_signal_handlers &&
- common_event_check_signal(std_ev->ev)) {
+ tevent_common_check_signal(std_ev->ev)) {
return 0;
}
@@ -504,7 +499,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
if (selrtn == -1 && errno == EINTR &&
std_ev->ev->num_signal_handlers) {
- common_event_check_signal(std_ev->ev);
+ tevent_common_check_signal(std_ev->ev);
return 0;
}
@@ -514,15 +509,15 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
made readable and that should have removed
the event, so this must be a bug. This is a
fatal error. */
- ev_debug(std_ev->ev, EV_DEBUG_FATAL,
- "ERROR: EBADF on std_event_loop_once\n");
+ tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL,
+ "ERROR: EBADF on std_event_loop_once\n");
std_ev->exit_code = EBADF;
return -1;
}
if (selrtn == 0 && tvalp) {
/* we don't care about a possible delay here */
- common_event_loop_timer_delay(std_ev->ev);
+ tevent_common_loop_timer_delay(std_ev->ev);
return 0;
}
@@ -533,8 +528,8 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
for (fde = std_ev->fd_events; fde; fde = fde->next) {
uint16_t flags = 0;
- if (FD_ISSET(fde->fd, &r_fds)) flags |= EVENT_FD_READ;
- if (FD_ISSET(fde->fd, &w_fds)) flags |= EVENT_FD_WRITE;
+ if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ;
+ if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
if (flags) {
fde->handler(std_ev->ev, fde, flags, fde->private_data);
if (destruction_count != std_ev->destruction_count) {
@@ -556,7 +551,7 @@ static int std_event_loop_once(struct tevent_context *ev)
struct std_event_context);
struct timeval tval;
- tval = common_event_loop_timer_delay(ev);
+ tval = tevent_common_loop_timer_delay(ev);
if (ev_timeval_is_zero(&tval)) {
return 0;
}
@@ -588,20 +583,21 @@ static int std_event_loop_wait(struct tevent_context *ev)
return std_ev->exit_code;
}
-static const struct event_ops std_event_ops = {
+static const struct tevent_ops std_event_ops = {
.context_init = std_event_context_init,
.add_fd = std_event_add_fd,
- .get_fd_flags = std_event_get_fd_flags,
+ .set_fd_close_fn= tevent_common_fd_set_close_fn,
+ .get_fd_flags = tevent_common_fd_get_flags,
.set_fd_flags = std_event_set_fd_flags,
- .add_timer = common_event_add_timed,
- .add_signal = common_event_add_signal,
+ .add_timer = tevent_common_add_timer,
+ .add_signal = tevent_common_add_signal,
.loop_once = std_event_loop_once,
.loop_wait = std_event_loop_wait,
};
-bool events_standard_init(void)
+bool tevent_standard_init(void)
{
- return event_register_backend("standard", &std_event_ops);
+ return tevent_register_backend("standard", &std_event_ops);
}