The branch, master has been updated via 23e77c5 messaging: Avoid crashes via 4ce599d messaging: Avoid a default tevent_fd via 6c21d99 messaging: Disable the correct fde on error via 7099ba8 messaging: Make messaging_dgm_register_tevent_context return a tevent_fd via fdc52ab messaging4: Postpone messages to the right tevent context via 6d3c064 messaging: Act on messages within the right context via 82dd356 messaging: Pass "ev" to messaging_dispatch_rec via 85c4137 messages_dgm_ref: Pass receiving "ev" to recv_cb via fc0b35b messages_dgm: Pass receiving "ev" to recv_cb via 88cdb23 messages_dgm: Pass down event_ctx one level via 56de9c5 messages_dgm: Drop a segment if we can't ship it for 60 seconds via 8a515a2 tevent: Add tevent_req_reset_endtime via cd1ab02 messaging: Optimize self-sends via 1cf8526 lib: Add messaging_rec_create via f9a8441 messaging: add an overflow test via ddffebc lib: Remove poll_funcs via f0e3ceb lib: Remove unix_msg via 40bbf94 messages_dgm: Convert to pthreadpool_tevent via 48425d2 pthreadpool: Add a small test for pthreadpool_tevent via ca43af9 pthreadpool_tevent: Drop running jobs on talloc_free via 9708ccc pthreadpool_tevent: Move the pthreadpool_tevent_job_state declaration via 1a3d081 pthreadpool_pipe: Implement EBUSY for _destroy via 77b7dea pthreadpool: Use detached threads via 2d6b6c2 pthreadpool: Make "shutdown" a bool via d5cc7be tevent: Make talloc_free safe when threaded_contexts exist via 5b3019c tevent: Add tevent_common_wakeup_fd() via d90f325 tevent: Rename wakeup fds via 0ecefd5 tevent: Add tevent_update_timer() via c834efa tevent: Factor out tevent_common_insert_timer via 85221cd messaging4: Fix signed/unsigned hickups from a782148 README.Coding: Add clang-format style file
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 23e77c56197d3db4271392ce1993930239e683be Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 30 06:42:40 2016 -0700 messaging: Avoid crashes With the latest patches we defer messages to a messaging_context's default context, the one that it was created with. This is another incarnation of 085542fc93b3 (I believe): messaging contexts can outlive their tevent contexts. In this case, the tevent_schedule_immediate(msg_ctx->event_ctx) has nothing to schedule on and will crash. This patch uses the fact that tevent_fd's can outlive their event_contexts. When the tevent_context dies, all tevent_fd's will get their flags set to 0. The tevent_handles in messages_dgm_ref always have TEVENT_FD_READ set, so a 0 flags field indicates the tevent_context has died. Signed-off-by: Volker Lendecke <v...@samba.org> Pair-Programmed-With: Stefan Metzmacher <me...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Wed Oct 5 03:51:43 CEST 2016 on sn-devel-144 commit 4ce599dcd2f5975df52b4392dc8a8e87b57a3f80 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 30 06:42:40 2016 -0700 messaging: Avoid a default tevent_fd Instead, rely on messaging_dgm_ref to always request a tevent_handle. Signed-off-by: Volker Lendecke <v...@samba.org> Pair-Programmed-With: Stefan Metzmacher <me...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 6c21d9977fc1c8b8cb3ffd4922ee7b1597452343 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 30 06:42:40 2016 -0700 messaging: Disable the correct fde on error We might be called from different event contexts and thus via different fde's Signed-off-by: Volker Lendecke <v...@samba.org> Pair-Programmed-With: Stefan Metzmacher <me...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 7099ba8770f3f38c37d9b910ac1898647bfd96f0 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 30 06:42:40 2016 -0700 messaging: Make messaging_dgm_register_tevent_context return a tevent_fd Signed-off-by: Volker Lendecke <v...@samba.org> Pair-Programmed-With: Stefan Metzmacher <me...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit fdc52abbf45c6362ae208142b0f3ee9a17e16fe4 Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 28 16:05:25 2016 -0700 messaging4: Postpone messages to the right tevent context Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 6d3c064f1a5d4471b5c68abf40ce21f71a55d564 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 19:35:10 2016 -0700 messaging: Act on messages within the right context Only look at "classic" messaging_register handlers in the main event context loop If we're sitting in a nested event context, only act upon the messaging_filtered_read ones that are registered in the nested context. Postpone everything else via an immediate to the main tevent context Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 82dd3562a5edc43e81a2ac897a329d6b06b097ad Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 19:28:10 2016 -0700 messaging: Pass "ev" to messaging_dispatch_rec Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 85c41375fd10d07a5dd6f3b65def3930eb65baf5 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 18:36:15 2016 -0700 messages_dgm_ref: Pass receiving "ev" to recv_cb Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit fc0b35b41cea5a02d9eec7dc438d54ed34758069 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 18:36:15 2016 -0700 messages_dgm: Pass receiving "ev" to recv_cb Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 88cdb233d3194f904f40cc689520d27c7cd6777d Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 17:07:20 2016 -0700 messages_dgm: Pass down event_ctx one level Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 56de9c53fb25dfff93f719e79bf7e3cc809f8a07 Author: Volker Lendecke <v...@samba.org> Date: Mon Sep 12 14:12:10 2016 +0200 messages_dgm: Drop a segment if we can't ship it for 60 seconds Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 8a515a2d10e63f5ad19089d9bd47d6f20c620c6c Author: Volker Lendecke <v...@samba.org> Date: Mon Sep 12 13:02:26 2016 +0200 tevent: Add tevent_req_reset_endtime We might decide at some point that we don't want a request to time out Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit cd1ab02530a696071b7d5f43c3e2ab94c6b1713b Author: Volker Lendecke <v...@samba.org> Date: Mon Jul 25 16:31:18 2016 +0200 messaging: Optimize self-sends We need to go through the event loop, which messaging_dgm_send does. We can also use a tevent_immediate for the same purpose. Right now the main user is messaging_ctdb: Here strace looks a bit weird when we receive a message. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1cf8526c6024dcf7f6fb7eba1394de6d05eefd25 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 19:06:56 2016 -0700 lib: Add messaging_rec_create Essentially a wrapper around messaging_rec_dup Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit f9a84411e81d67311452228979648c9dd87a4631 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 16:51:25 2016 +0200 messaging: add an overflow test Send 1000 messages without picking them up. Then destroy the sending messaging context. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit ddffebc0fed80c9937e39c3a8b6b39fc78c2c372 Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 28 14:44:03 2016 -0700 lib: Remove poll_funcs unix_msg was the only user Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit f0e3cebc54657dab003c9ff139f5db1730f607a9 Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 28 14:35:21 2016 -0700 lib: Remove unix_msg Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 40bbf9494f675d1d4ac226d77978d25ca6bfd78f Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 16:51:00 2016 +0200 messages_dgm: Convert to pthreadpool_tevent This itself adds a lot of code, however it removes the unix_msg library. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 48425d2cf096a860817cf945eeaf8e95db035e80 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 16:42:05 2016 +0200 pthreadpool: Add a small test for pthreadpool_tevent Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit ca43af97d219f2de836a50ecaf24532445a3da66 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 13:28:51 2016 +0200 pthreadpool_tevent: Drop running jobs on talloc_free Enable us to destroy a pthreadpool_tevent structure with active jobs Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 9708ccc6d7d54211395b2a53d567118cb37bd308 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 13:27:13 2016 +0200 pthreadpool_tevent: Move the pthreadpool_tevent_job_state declaration Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1a3d081c995de9ff8a7047e9b77cd532c3dffa97 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 15:18:41 2016 +0200 pthreadpool_pipe: Implement EBUSY for _destroy Restore EBUSY on pthreadpool_pipe_destroy. We need to count jobs in pthreadpool_pipe so that pthreadpool can exit with active jobs. Unfortunately this makes pthreadpool_pipe_add_job non-threadsafe. We could add mutexes around "num_jobs", but this would mean another set of pthread_atfork functions. As we don't use threaded pthreadpool_pipe_add_job except in the tests, just remove the tests... Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 77b7dea2d988a9944f795e2efae24aeb16009f5f Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 9 13:07:57 2016 +0200 pthreadpool: Use detached threads So far we used joinable threads. This prevented pthreadpool_destroy with blocked threads. This patch converts pthreadpool to detached threads. Now pthreadpool_destroy does not have to wait for the idle threads to finish, it can immediately return. pthreadpool_destroy will tell all threads to exit, and the last active thread will actually free(pthreadpool). Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 2d6b6c24469d2207132d16cb23b32697e3371134 Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 7 20:37:21 2016 +0200 pthreadpool: Make "shutdown" a bool Just a small cleanup Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit d5cc7be95994b24f30b821cf5f666c9b9209400c Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 7 20:25:36 2016 +0200 tevent: Make talloc_free safe when threaded_contexts exist I did not find a way to do this safely without a mutex per threaded_context. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 5b3019cb91f732f95f65c228a2483788f54faa8b Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 7 19:47:55 2016 +0200 tevent: Add tevent_common_wakeup_fd() This prepares tevent run-down with active threads. It has the advantage to not depend on talloc'ed structs. It is needed to make talloc_free(tevent_context) safe when tevent_threaded_contexts are still around. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit d90f325878f8aab5c66ac304e501627040788138 Author: Volker Lendecke <v...@samba.org> Date: Wed Sep 7 19:17:21 2016 +0200 tevent: Rename wakeup fds This makes the reading end of the signalling pipe special: If we have eventfd, this is the same as the write fd. Without eventfd, it will have to be a separate fd. This moves the requirement to #ifdef from the writing end to the reading end. Why? We'll use the writing end somewhere else too soon, and this patch avoids an #ifdef in that new place. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 0ecefd5bf91ae8297569dc862d7259e942d895fe Author: Volker Lendecke <v...@samba.org> Date: Wed Aug 31 15:39:59 2016 +0200 tevent: Add tevent_update_timer() This will be a quicker way to time out sending sockets in messaging_dgm. Right now cleanup of out-sockets is a bit coarse. The ideal would be to kill a socket after being idle n seconds. This would mean to free and re-install a timer on every packet. tevent_update_timer will be quite a bit cheaper. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit c834efabd685198c570503bfc8394ff80899cef5 Author: Volker Lendecke <v...@samba.org> Date: Wed Aug 31 15:03:16 2016 +0200 tevent: Factor out tevent_common_insert_timer Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 85221cd882cd0622bdab30d60e7907e520019905 Author: Volker Lendecke <v...@samba.org> Date: Fri Sep 23 18:43:04 2016 -0700 messaging4: Fix signed/unsigned hickups Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/poll_funcs/poll_funcs.h | 131 --- lib/poll_funcs/poll_funcs_tevent.c | 684 ---------------- lib/poll_funcs/poll_funcs_tevent.h | 38 - lib/poll_funcs/wscript_build | 5 - lib/tevent/ABI/tevent-0.9.30.sigs | 3 + lib/tevent/tevent.c | 99 ++- lib/tevent/tevent.h | 17 + lib/tevent/tevent_internal.h | 10 +- lib/tevent/tevent_req.c | 5 + lib/tevent/tevent_threads.c | 38 +- lib/tevent/tevent_timed.c | 88 ++- source3/lib/messages.c | 169 +++- source3/lib/messages_dgm.c | 951 ++++++++++++++++++++-- source3/lib/messages_dgm.h | 7 +- source3/lib/messages_dgm_ref.c | 42 +- source3/lib/messages_dgm_ref.h | 3 +- source3/lib/pthreadpool/pthreadpool.c | 199 ++--- source3/lib/pthreadpool/pthreadpool.h | 9 +- source3/lib/pthreadpool/pthreadpool_pipe.c | 28 +- source3/lib/pthreadpool/pthreadpool_tevent.c | 39 +- source3/lib/pthreadpool/tests.c | 302 +++---- source3/lib/unix_msg/test_drain.c | 83 -- source3/lib/unix_msg/test_source.c | 93 --- source3/lib/unix_msg/tests.c | 271 ------- source3/lib/unix_msg/unix_msg.c | 1094 -------------------------- source3/lib/unix_msg/unix_msg.h | 121 --- source3/lib/unix_msg/wscript_build | 18 - source3/wscript_build | 6 +- source4/lib/messaging/messaging.c | 75 +- source4/lib/messaging/tests/messaging.c | 76 ++ wscript_build | 1 - 31 files changed, 1655 insertions(+), 3050 deletions(-) delete mode 100644 lib/poll_funcs/poll_funcs.h delete mode 100644 lib/poll_funcs/poll_funcs_tevent.c delete mode 100644 lib/poll_funcs/poll_funcs_tevent.h delete mode 100644 lib/poll_funcs/wscript_build delete mode 100644 source3/lib/unix_msg/test_drain.c delete mode 100644 source3/lib/unix_msg/test_source.c delete mode 100644 source3/lib/unix_msg/tests.c delete mode 100644 source3/lib/unix_msg/unix_msg.c delete mode 100644 source3/lib/unix_msg/unix_msg.h delete mode 100644 source3/lib/unix_msg/wscript_build Changeset truncated at 500 lines: diff --git a/lib/poll_funcs/poll_funcs.h b/lib/poll_funcs/poll_funcs.h deleted file mode 100644 index b16f07f..0000000 --- a/lib/poll_funcs/poll_funcs.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Copyright (C) Volker Lendecke 2013 - * - * 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, - * 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/>. - */ - -/** - * @file poll_funcs.h - * - * @brief event loop abstraction - */ - -/* - * This is inspired by AvahiWatch, the avahi event loop abstraction. - */ - -#ifndef __POLL_FUNCS_H__ -#define __POLL_FUNCS_H__ - -#include "replace.h" - -/** - * poll_watch and poll_timeout are undefined here, every implementation can - * implement its own structures. - */ - -struct poll_watch; -struct poll_timeout; - -struct poll_funcs { - - /** - * @brief Create a new file descriptor watch - * - * @param[in] funcs The callback array - * @param[in] fd The fd to watch - * @param[in] events POLLIN and POLLOUT or'ed together - * @param[in] callback Function to call by the implementation - * @param[in] private_data Pointer to give back to callback - * - * @return A new poll_watch struct - */ - - struct poll_watch *(*watch_new)( - const struct poll_funcs *funcs, int fd, short events, - void (*callback)(struct poll_watch *w, int fd, - short events, void *private_data), - void *private_data); - - /** - * @brief Change the watched events for a struct poll_watch - * - * @param[in] w The poll_watch to change - * @param[in] events new POLLIN and POLLOUT or'ed together - */ - - void (*watch_update)(struct poll_watch *w, short events); - - /** - * @brief Read events currently watched - * - * @param[in] w The poll_watch to inspect - * - * @returns The events currently watched - */ - - short (*watch_get_events)(struct poll_watch *w); - - /** - * @brief Free a struct poll_watch - * - * @param[in] w The poll_watch struct to free - */ - - void (*watch_free)(struct poll_watch *w); - - - /** - * @brief Create a new timeout watch - * - * @param[in] funcs The callback array - * @param[in] tv The time when the timeout should trigger - * @param[in] callback Function to call at time "tv" - * @param[in] private_data Pointer to give back to callback - * - * @return A new poll_timeout struct - */ - - struct poll_timeout *(*timeout_new)( - const struct poll_funcs *funcs, const struct timeval tv, - void (*callback)(struct poll_timeout *t, void *private_data), - void *private_data); - - /** - * @brief Change the timeout of a watch - * - * @param[in] t The timeout watch to change - * @param[in] tv The new trigger time - */ - - void (*timeout_update)(struct poll_timeout *t, - const struct timeval tv); - - /** - * @brief Free a poll_timeout - * - * @param[in] t The poll_timeout to free - */ - - void (*timeout_free)(struct poll_timeout *t); - - /** - * @brief private data for use by the implementation - */ - - void *private_data; -}; - -#endif diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c deleted file mode 100644 index 4dd09a2..0000000 --- a/lib/poll_funcs/poll_funcs_tevent.c +++ /dev/null @@ -1,684 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Copyright (C) Volker Lendecke 2013,2014 - * - * 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, - * 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/>. - */ - -#include "poll_funcs_tevent.h" -#include "tevent.h" -#include "system/select.h" -#include "lib/util/dlinklist.h" - -/* - * A poll_watch is asked for by the engine using this library via - * funcs->watch_new(). It represents interest in "fd" becoming readable or - * writable. - */ - -struct poll_watch { - struct poll_funcs_state *state; - size_t slot; /* index into state->watches[] */ - int fd; - int events; - void (*callback)(struct poll_watch *w, int fd, short events, - void *private_data); - void *private_data; -}; - -struct poll_timeout { - struct poll_funcs_state *state; - size_t slot; /* index into state->timeouts[] */ - struct timeval tv; - void (*callback)(struct poll_timeout *t, void *private_data); - void *private_data; -}; - -struct poll_funcs_state { - /* - * "watches" is the array of all watches that we have handed out via - * funcs->watch_new(). The "watches" array can contain NULL pointers. - */ - struct poll_watch **watches; - - /* - * Like "watches" for timeouts; - */ - struct poll_timeout **timeouts; - - /* - * "contexts is the array of tevent_contexts that serve - * "watches". "contexts" can contain NULL pointers. - */ - struct poll_funcs_tevent_context **contexts; -}; - -struct poll_funcs_tevent_context { - struct poll_funcs_tevent_handle *handles; - struct poll_funcs_state *state; - unsigned slot; /* index into state->contexts[] */ - struct tevent_context *ev; - struct tevent_fd **fdes; /* same indexes as state->watches[] */ - struct tevent_timer **timers; /* same indexes as state->timeouts[] */ -}; - -/* - * poll_funcs_tevent_register() hands out a struct poll_funcs_tevent_handle as - * a void *. poll_funcs_tevent_register allows tevent_contexts to be - * registered multiple times, and we can't add a tevent_fd for the same fd's - * multiple times. So we have to share one poll_funcs_tevent_context. - */ -struct poll_funcs_tevent_handle { - struct poll_funcs_tevent_handle *prev, *next; - struct poll_funcs_tevent_context *ctx; -}; - -static uint16_t poll_events_to_tevent(short events) -{ - uint16_t ret = 0; - - if (events & POLLIN) { - ret |= TEVENT_FD_READ; - } - if (events & POLLOUT) { - ret |= TEVENT_FD_WRITE; - } - return ret; -} - -static short tevent_to_poll_events(uint16_t flags) -{ - short ret = 0; - - if (flags & TEVENT_FD_READ) { - ret |= POLLIN; - } - if (flags & TEVENT_FD_WRITE) { - ret |= POLLOUT; - } - return ret; -} - -/* - * Find or create a free slot in state->watches[] - */ -static bool poll_funcs_watch_find_slot(struct poll_funcs_state *state, - size_t *slot) -{ - struct poll_watch **watches; - size_t i, num_watches, num_contexts; - - num_watches = talloc_array_length(state->watches); - - for (i=0; i<num_watches; i++) { - if (state->watches[i] == NULL) { - *slot = i; - return true; - } - } - - watches = talloc_realloc(state, state->watches, struct poll_watch *, - num_watches + 1); - if (watches == NULL) { - return false; - } - watches[num_watches] = NULL; - state->watches = watches; - - num_contexts = talloc_array_length(state->contexts); - - for (i=0; i<num_contexts; i++) { - struct tevent_fd **fdes; - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - fdes = talloc_realloc(c, c->fdes, struct tevent_fd *, - num_watches + 1); - if (fdes == NULL) { - state->watches = talloc_realloc( - state, state->watches, struct poll_watch *, - num_watches); - return false; - } - c->fdes = fdes; - - fdes[num_watches] = NULL; - } - - *slot = num_watches; - - return true; -} - -static void poll_funcs_fde_handler(struct tevent_context *ev, - struct tevent_fd *fde, uint16_t flags, - void *private_data); -static int poll_watch_destructor(struct poll_watch *w); - -static struct poll_watch *tevent_watch_new( - const struct poll_funcs *funcs, int fd, short events, - void (*callback)(struct poll_watch *w, int fd, short events, - void *private_data), - void *private_data) -{ - struct poll_funcs_state *state = talloc_get_type_abort( - funcs->private_data, struct poll_funcs_state); - struct poll_watch *w; - size_t i, slot, num_contexts; - - if (!poll_funcs_watch_find_slot(state, &slot)) { - return NULL; - } - - w = talloc(state->watches, struct poll_watch); - if (w == NULL) { - return NULL; - } - w->state = state; - w->slot = slot; - w->fd = fd; - w->events = poll_events_to_tevent(events); - w->fd = fd; - w->callback = callback; - w->private_data = private_data; - state->watches[slot] = w; - - talloc_set_destructor(w, poll_watch_destructor); - - num_contexts = talloc_array_length(state->contexts); - - for (i=0; i<num_contexts; i++) { - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - c->fdes[slot] = tevent_add_fd(c->ev, c->fdes, w->fd, w->events, - poll_funcs_fde_handler, w); - if (c->fdes[slot] == NULL) { - goto fail; - } - } - return w; - -fail: - TALLOC_FREE(w); - return NULL; -} - -static int poll_watch_destructor(struct poll_watch *w) -{ - struct poll_funcs_state *state = w->state; - size_t num_contexts = talloc_array_length(state->contexts); - size_t slot = w->slot; - size_t i; - - TALLOC_FREE(state->watches[slot]); - - for (i=0; i<num_contexts; i++) { - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - TALLOC_FREE(c->fdes[slot]); - } - - return 0; -} - -static void tevent_watch_update(struct poll_watch *w, short events) -{ - struct poll_funcs_state *state = w->state; - size_t num_contexts = talloc_array_length(state->contexts); - size_t slot = w->slot; - size_t i; - - w->events = poll_events_to_tevent(events); - - for (i=0; i<num_contexts; i++) { - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - tevent_fd_set_flags(c->fdes[slot], w->events); - } -} - -static short tevent_watch_get_events(struct poll_watch *w) -{ - return tevent_to_poll_events(w->events); -} - -static void tevent_watch_free(struct poll_watch *w) -{ - TALLOC_FREE(w); -} - -static bool poll_funcs_timeout_find_slot(struct poll_funcs_state *state, - size_t *slot) -{ - struct poll_timeout **timeouts; - size_t i, num_timeouts, num_contexts; - - num_timeouts = talloc_array_length(state->timeouts); - - for (i=0; i<num_timeouts; i++) { - if (state->timeouts[i] == NULL) { - *slot = i; - return true; - } - } - - timeouts = talloc_realloc(state, state->timeouts, - struct poll_timeout *, - num_timeouts + 1); - if (timeouts == NULL) { - return false; - } - timeouts[num_timeouts] = NULL; - state->timeouts = timeouts; - - num_contexts = talloc_array_length(state->contexts); - - for (i=0; i<num_contexts; i++) { - struct tevent_timer **timers; - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - timers = talloc_realloc(c, c->timers, struct tevent_timer *, - num_timeouts + 1); - if (timers == NULL) { - state->timeouts = talloc_realloc( - state, state->timeouts, struct poll_timeout *, - num_timeouts); - return false; - } - c->timers = timers; - - timers[num_timeouts] = NULL; - } - - *slot = num_timeouts; - - return true; -} - -static void poll_funcs_timer_handler(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval current_time, - void *private_data); -static int poll_timeout_destructor(struct poll_timeout *t); - -static struct poll_timeout *tevent_timeout_new( - const struct poll_funcs *funcs, const struct timeval tv, - void (*callback)(struct poll_timeout *t, void *private_data), - void *private_data) -{ - struct poll_funcs_state *state = talloc_get_type_abort( - funcs->private_data, struct poll_funcs_state); - struct poll_timeout *t; - size_t i, slot, num_contexts; - - if (!poll_funcs_timeout_find_slot(state, &slot)) { - return NULL; - } - - t = talloc(state->timeouts, struct poll_timeout); - if (t == NULL) { - return NULL; - } - t->state = state; - t->slot = slot; - t->tv = tv; - t->callback = callback; - t->private_data = private_data; - - talloc_set_destructor(t, poll_timeout_destructor); - - num_contexts = talloc_array_length(state->contexts); - - for (i=0; i<num_contexts; i++) { - struct poll_funcs_tevent_context *c = state->contexts[i]; - if (c == NULL) { - continue; - } - c->timers[slot] = tevent_add_timer( -- Samba Shared Repository