Unix SMB/CIFS implementation.
main select loop and event handling
Copyright (C) Andrew Tridgell 2003-2005
- Copyright (C) Stefan Metzmacher 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ Copyright (C) Stefan Metzmacher 2005-2009
+
+ ** NOTE! The following LGPL license applies to the tevent
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
/* a pointer back to the generic event_context */
struct tevent_context *ev;
- /* list of filedescriptor events */
- struct tevent_fd *fd_events;
-
/* the maximum file descriptor number in fd_events */
int maxfd;
return;
}
std_ev->pid = getpid();
- for (fde=std_ev->fd_events;fde;fde=fde->next) {
+ for (fde=std_ev->ev->fd_events;fde;fde=fde->next) {
epoll_add_event(std_ev, fde);
}
}
timeout = ((tvalp->tv_usec+999) / 1000) + (tvalp->tv_sec*1000);
}
- if (std_ev->ev->num_signal_handlers &&
+ if (std_ev->ev->signal_events &&
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 (ret == -1 && errno == EINTR && std_ev->ev->signal_events) {
if (tevent_common_check_signal(std_ev->ev)) {
return 0;
}
struct tevent_fd *fde;
std_ev->maxfd = 0;
- for (fde = std_ev->fd_events; fde; fde = fde->next) {
+ for (fde = std_ev->ev->fd_events; fde; fde = fde->next) {
if (fde->fd > std_ev->maxfd) {
std_ev->maxfd = fde->fd;
}
static int std_event_fd_destructor(struct tevent_fd *fde)
{
struct tevent_context *ev = fde->event_ctx;
- struct std_event_context *std_ev = talloc_get_type(ev->additional_data,
- struct std_event_context);
+ struct std_event_context *std_ev = NULL;
- epoll_check_reopen(std_ev);
+ if (ev) {
+ std_ev = talloc_get_type(ev->additional_data,
+ struct std_event_context);
- if (std_ev->maxfd == fde->fd) {
- std_ev->maxfd = EVENT_INVALID_MAXFD;
- }
+ epoll_check_reopen(std_ev);
- DLIST_REMOVE(std_ev->fd_events, fde);
- std_ev->destruction_count++;
+ if (std_ev->maxfd == fde->fd) {
+ std_ev->maxfd = EVENT_INVALID_MAXFD;
+ }
- epoll_del_event(std_ev, fde);
+ std_ev->destruction_count++;
- if (fde->close_fn) {
- fde->close_fn(ev, fde, fde->fd, fde->private_data);
- fde->fd = -1;
+ epoll_del_event(std_ev, fde);
}
- return 0;
+ return tevent_common_fd_destructor(fde);
}
/*
epoll_check_reopen(std_ev);
- fde = talloc(mem_ctx?mem_ctx:ev, struct tevent_fd);
+ fde = tevent_common_add_fd(ev, mem_ctx, fd, flags,
+ handler, private_data,
+ handler_name, location);
if (!fde) return NULL;
- fde->event_ctx = ev;
- 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;
-
- DLIST_ADD(std_ev->fd_events, fde);
if ((std_ev->maxfd != EVENT_INVALID_MAXFD)
&& (fde->fd > std_ev->maxfd)) {
std_ev->maxfd = fde->fd;
FD_ZERO(&w_fds);
/* setup any fd events */
- for (fde = std_ev->fd_events; fde; fde = fde->next) {
+ for (fde = std_ev->ev->fd_events; fde; fde = fde->next) {
if (fde->flags & TEVENT_FD_READ) {
FD_SET(fde->fd, &r_fds);
}
}
}
- if (std_ev->ev->num_signal_handlers &&
+ if (std_ev->ev->signal_events &&
tevent_common_check_signal(std_ev->ev)) {
return 0;
}
selrtn = select(std_ev->maxfd+1, &r_fds, &w_fds, NULL, tvalp);
if (selrtn == -1 && errno == EINTR &&
- std_ev->ev->num_signal_handlers) {
+ std_ev->ev->signal_events) {
tevent_common_check_signal(std_ev->ev);
return 0;
}
/* at least one file descriptor is ready - check
which ones and call the handler, being careful to allow
the handler to remove itself when called */
- for (fde = std_ev->fd_events; fde; fde = fde->next) {
+ for (fde = std_ev->ev->fd_events; fde; fde = fde->next) {
uint16_t flags = 0;
if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ;
struct std_event_context);
std_ev->exit_code = 0;
- while (std_ev->fd_events && std_ev->exit_code == 0) {
+ while (ev->fd_events && std_ev->exit_code == 0) {
if (std_event_loop_once(ev) != 0) {
break;
}