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.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 1c99408b8d..5769eac589 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -30,7 +30,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 +64,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 +130,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 +166,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 +209,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 +217,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 +266,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 +285,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 +301,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 +310,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,7 +392,7 @@ static int std_event_fd_destructor(struct tevent_fd *fde)
epoll_del_event(std_ev, fde);
- if (fde->flags & EVENT_FD_AUTOCLOSE) {
+ if (fde->flags & TEVENT_FD_AUTOCLOSE) {
close(fde->fd);
fde->fd = -1;
}
@@ -405,9 +405,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);
@@ -487,16 +489,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 +506,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 +516,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 +535,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 +558,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 +590,20 @@ 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_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);
}