[SCM] Samba Shared Repository - branch v3-4-test updated - release-4-0-0alpha7-505-g00b65cc

Stefan Metzmacher metze at samba.org
Wed Mar 18 15:49:04 GMT 2009


The branch, v3-4-test has been updated
       via  00b65cc6ebcb4c67259e7fa618f6d961f7117396 (commit)
       via  ca31920af281ba9ea8f466ed0264118737a1b055 (commit)
       via  e270b4f0f62699469cbaad024c893fe84142a256 (commit)
       via  3ccc0bd5ea15da6b4daa53d9dcfb6a283330493d (commit)
       via  c43ef1f1eeb9176cda0d69b5f17c2b4885a0772b (commit)
       via  c9eac30fbbd4af6d73b803b19f0dec8ce72baf59 (commit)
       via  a527e24b80abf5aeaafdd67db21b5b021d1effe0 (commit)
       via  a6a4acddbcfcb36d581c1c7d15ddb8405c0b2bb2 (commit)
       via  c0a0f504e1477648542aae27b8a58d4db4867d84 (commit)
       via  8053941b377d3fd2e58e67f68eecb2551be49c10 (commit)
       via  7fcb16a79681a24ca3b96ec73bc44b43e57c3c8f (commit)
       via  d88a254c5d2fbdda642d469924411d4d6d5f8422 (commit)
       via  54af7b9da45dcef881d9fee7c414d363ca6cdab4 (commit)
       via  ba8a0b59d6f486f09d73e0bcac5712584c9580cc (commit)
       via  de7125980d237e9a8aa126f155bbc84c96bad37e (commit)
       via  f18ff6728e97580ff980385137e8e7973ae1d785 (commit)
       via  c742112da583809f47e40f2e4b48713d2e81edda (commit)
       via  c0bc27fc57260191e35464b63e114163d291d4da (commit)
       via  1eb7ad106499865713c28847f491aae10f37beb7 (commit)
       via  606b55d220c354f11299d633b1387afd4bc47c55 (commit)
       via  646c93ee8f7e6f52b55900923b5db9d7a1571742 (commit)
       via  5c75c1406fd6bdd6319070cb4098929c28eeba94 (commit)
       via  f136ed96e46c1d4b6aec13daf468ada2fdf59715 (commit)
       via  868cc328b189144c49901692206534c9b2729fbd (commit)
       via  82f9d29c4b6cd5cc1c5901d801a28c2f649d4205 (commit)
       via  3106e9fac2316cbbb06261f54aa86a7a2e77e2b4 (commit)
      from  d001b199a1cf73b7c7f4574191698325871527d9 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-4-test


- Log -----------------------------------------------------------------
commit 00b65cc6ebcb4c67259e7fa618f6d961f7117396
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 17:27:30 2009 +0100

    s3:winbindd: accept new connections via fd events
    
    metze
    (cherry picked from commit 93c2057c8b5a3976cda65a9d27dc4dbb9c5c550a)

commit ca31920af281ba9ea8f466ed0264118737a1b055
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 16:14:20 2009 +0100

    s3:winbindd: move non event related code out of process_loop() in the the caller
    
    metze
    (cherry picked from commit 3b8dd79f2bc775ed94130565ec2c4383a4864348)

commit e270b4f0f62699469cbaad024c893fe84142a256
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 16:06:12 2009 +0100

    s3:winbindd: remove unused close_winbindd_socket() function
    
    metze
    (cherry picked from commit 0685031ccfc09feb0ad070df1c1a1d0cef5874f2)

commit 3ccc0bd5ea15da6b4daa53d9dcfb6a283330493d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 15:55:39 2009 +0100

    s3:smbd: use tevent_loop_once() in the parent event loop
    
    metze
    (cherry picked from commit 450252d2a1981fb04eb62eb095c1b762a96f7727)

commit c43ef1f1eeb9176cda0d69b5f17c2b4885a0772b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 15:47:57 2009 +0100

    s3:printing: use tevent_loop_wait() instead of manual looping
    
    metze
    (cherry picked from commit b659daf81f31678f7447545d015bd9d1db8811b9)

commit c9eac30fbbd4af6d73b803b19f0dec8ce72baf59
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:56:11 2009 +0100

    s3:printing: use a fd event to monitor the pipe to the parent
    
    metze
    (cherry picked from commit 339ea0503d5ce3bf85cf61528956345c73c668c6)

commit a527e24b80abf5aeaafdd67db21b5b021d1effe0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:48:40 2009 +0100

    s3:smbd: don't exit the parent when we have no connections
    
    This code path can't really happen anymore, because
    launchd support was removed with commit e5a951325a6cac8567af3a66de6d2df577508ae4.
    But it's confusing to have that code there...
    
    metze
    (cherry picked from commit 445b37f4f35ff4256c46dbacc2d3b3a1e47e62b2)

commit a6a4acddbcfcb36d581c1c7d15ddb8405c0b2bb2
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 20:18:31 2009 +0100

    s4:build: require tevent 0.9.5
    
    metze
    (cherry picked from commit e95d0b548e344dbc8cb3dd0a0f29854711bd0cac)

commit c0a0f504e1477648542aae27b8a58d4db4867d84
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 20:18:01 2009 +0100

    tevent: change version to 0.9.5 after the ABI has changed
    
    metze
    (cherry picked from commit 7d07266ca26f7069269601043b713a91f1a4693c)

commit 8053941b377d3fd2e58e67f68eecb2551be49c10
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 20:13:34 2009 +0100

    tevent: store the location where a request was finished
    
    This is very useful to find bugs.
    You can use 'p *req' in gdb to show where
    tevent_req_done(), tevent_req_error() or tevent_req_nomem()
    was called.
    
    metze
    (cherry picked from commit 9eaf53d98eced9ea70f411b9936b475c42e4d490)

commit 7fcb16a79681a24ca3b96ec73bc44b43e57c3c8f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 10:42:55 2009 +0100

    tevent: use an immediate event as trigger for tevent_queue
    
    metze
    (cherry picked from commit 3a831e46204979550dc6ee7652cea6b8296f10c1)

commit d88a254c5d2fbdda642d469924411d4d6d5f8422
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 10:18:34 2009 +0100

    tevent: use an immediate event fot tevent_req_post()
    
    Now tevent_req_post() never fails
    
    metze
    (cherry picked from commit 4bdf299385220988a4fe16f82aab528283204c7f)

commit 54af7b9da45dcef881d9fee7c414d363ca6cdab4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Mar 17 10:17:50 2009 +0100

    tevent: use TALLOC_FREE() in tevent_req.c
    
    metze
    (cherry picked from commit a78cd2a24b818bc7d843a8e56ffaafc9f6578662)

commit ba8a0b59d6f486f09d73e0bcac5712584c9580cc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 15:06:52 2009 +0100

    s3:events: add support for immediate events
    
    metze
    (cherry picked from commit 6c290586e41b3f5f7748a5b8c782be67cafe6c57)

commit de7125980d237e9a8aa126f155bbc84c96bad37e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 13 15:47:33 2009 +0100

    tevent: add support for immediate events
    
    They're like directly triggered timed events,
    but you can preallocated them and scheduling them
    will not fail.
    
    metze
    (cherry picked from commit 66886f8966dff8a980a5b9d2daa3fbb20fe5ca8e)

commit f18ff6728e97580ff980385137e8e7973ae1d785
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:45:42 2009 +0100

    s3:events: make use of tevent_common_loop_wait()
    
    metze
    (cherry picked from commit d27be1d5fa3fdcaac07b527ad14b0d10ef27c0bb)

commit c742112da583809f47e40f2e4b48713d2e81edda
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:15:07 2009 +0100

    tevent: add tevent_common_loop_wait() helper function and use it
    
    tevent_loop_wait should do the same for all backends.
    It should loop as long as we have pending events.
    
    metze
    (cherry picked from commit 940e61846e97ba62153d5b977b0823f196607743)

commit c0bc27fc57260191e35464b63e114163d291d4da
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 12:45:48 2009 +0100

    tevent: check signal events first in event_loop_once
    
    We also check for signal events directly before and after
    the select/epoll calls.
    
    metze
    (cherry picked from commit 0139befb915006d6ec9fec2734057c5c50b3c383)

commit 1eb7ad106499865713c28847f491aae10f37beb7
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 12:34:23 2009 +0100

    tevent: let tevent_loop_once() just run one fd event
    
    This makes the logic much simpler for the callers,
    and matches the samba3 behavior.
    
    If needed we can add performance tunning for tevent_loop_wait()
    later.
    
    metze
    (cherry picked from commit 3af7db3dce0e5529114f6969e9905c6d4c65dfe8)

commit 606b55d220c354f11299d633b1387afd4bc47c55
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Mar 15 16:35:13 2009 +0100

    configure: Add common file with minimum versions of external libraries.
    (cherry picked from commit 0ea702efaeaadcdcb05e99e838dae1b2dbdd95b9)

commit 646c93ee8f7e6f52b55900923b5db9d7a1571742
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Mar 15 14:55:12 2009 +0100

    Depend on newer talloc for Samba 4 in the merged build as well.
    (cherry picked from commit 74299582c4989d00a45962836bb02cc7f4b2dd20)

commit 5c75c1406fd6bdd6319070cb4098929c28eeba94
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun Mar 15 03:05:46 2009 +0100

    Remove unused CONST_DISCARD macro.
    (cherry picked from commit 75783473d180661257e3f0e3d300179caf34bd8e)

commit f136ed96e46c1d4b6aec13daf468ada2fdf59715
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 13 15:50:23 2009 +0100

    s4:build: require tevent 0.9.4
    
    metze
    (cherry picked from commit 1355dc2fd3a10c54fc3534409b78972d59d59b30)

commit 868cc328b189144c49901692206534c9b2729fbd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 13 15:49:35 2009 +0100

    tevent: change version to 0.9.4 as the ABI has changed
    
    metze
    (cherry picked from commit 868f3f5f32eccdf68590cdfc5c42e1af970410d7)

commit 82f9d29c4b6cd5cc1c5901d801a28c2f649d4205
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Mar 14 21:06:41 2009 +0100

    Fix fallback if system doesn't provide talloc.
    (cherry picked from commit 0c72c503faa0506ed25067e623f9263da8e2c94c)

commit 3106e9fac2316cbbb06261f54aa86a7a2e77e2b4
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Mar 14 20:56:26 2009 +0100

    Allow using external libtalloc.
    (cherry picked from commit 61447dfbbfe275e3704ff939480f38629b52064a)

-----------------------------------------------------------------------

Summary of changes:
 lib/tevent/configure.ac           |    2 +-
 lib/tevent/libtevent.m4           |    3 +-
 lib/tevent/tevent.c               |   77 +++++++++++++++
 lib/tevent/tevent.h               |   41 +++++++--
 lib/tevent/tevent_epoll.c         |   62 ++++--------
 lib/tevent/tevent_immediate.c     |  139 ++++++++++++++++++++++++++
 lib/tevent/tevent_internal.h      |   53 ++++++++++-
 lib/tevent/tevent_queue.c         |   99 +++++++++++--------
 lib/tevent/tevent_req.c           |   74 +++++++-------
 lib/tevent/tevent_select.c        |   60 ++++-------
 lib/tevent/tevent_standard.c      |   69 +++++---------
 {lib/tevent => m4}/pkg.m4         |    0 
 source3/autogen.sh                |    2 +-
 source3/configure.in              |   21 ++++-
 source3/lib/events.c              |   35 +++----
 source3/printing/printing.c       |   82 ++++++----------
 source3/samba4.m4                 |   10 +-
 source3/smbd/server.c             |   46 +--------
 source3/winbindd/winbindd.c       |  195 +++++++++++++++++++++++--------------
 source3/winbindd/winbindd_proto.h |    1 -
 source3/winbindd/winbindd_util.c  |   18 ----
 source4/configure.ac              |   10 +-
 source4/include/includes.h        |    4 -
 source4/min_versions.m4           |    6 +
 24 files changed, 675 insertions(+), 434 deletions(-)
 create mode 100644 lib/tevent/tevent_immediate.c
 copy {lib/tevent => m4}/pkg.m4 (100%)
 create mode 100644 source4/min_versions.m4


Changeset truncated at 500 lines:

diff --git a/lib/tevent/configure.ac b/lib/tevent/configure.ac
index 4333461..171a408 100644
--- a/lib/tevent/configure.ac
+++ b/lib/tevent/configure.ac
@@ -1,5 +1,5 @@
 AC_PREREQ(2.50)
-AC_INIT(tevent, 0.9.3)
+AC_INIT(tevent, 0.9.5)
 AC_CONFIG_SRCDIR([tevent.c])
 AC_CONFIG_HEADER(config.h)
 
diff --git a/lib/tevent/libtevent.m4 b/lib/tevent/libtevent.m4
index c316823..20730b1 100644
--- a/lib/tevent/libtevent.m4
+++ b/lib/tevent/libtevent.m4
@@ -26,7 +26,8 @@ AC_SUBST(TEVENT_LIBS)
 
 TEVENT_CFLAGS="-I$teventdir"
 
-TEVENT_OBJ="tevent.o tevent_fd.o tevent_timed.o tevent_signal.o tevent_debug.o tevent_util.o"
+TEVENT_OBJ="tevent.o tevent_debug.o tevent_util.o"
+TEVENT_OBJ="$TEVENT_OBJ tevent_fd.o tevent_timed.o tevent_immediate.o tevent_signal.o"
 TEVENT_OBJ="$TEVENT_OBJ tevent_req.o tevent_wakeup.o tevent_queue.o"
 TEVENT_OBJ="$TEVENT_OBJ tevent_standard.o tevent_select.o"
 
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 867cfc0..ba2d93f 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -143,6 +143,7 @@ int tevent_common_context_destructor(struct tevent_context *ev)
 {
 	struct tevent_fd *fd, *fn;
 	struct tevent_timer *te, *tn;
+	struct tevent_immediate *ie, *in;
 	struct tevent_signal *se, *sn;
 
 	if (ev->pipe_fde) {
@@ -162,6 +163,13 @@ int tevent_common_context_destructor(struct tevent_context *ev)
 		DLIST_REMOVE(ev->timer_events, te);
 	}
 
+	for (ie = ev->immediate_events; ie; ie = in) {
+		in = ie->next;
+		ie->event_ctx = NULL;
+		ie->cancel_fn = NULL;
+		DLIST_REMOVE(ev->immediate_events, ie);
+	}
+
 	for (se = ev->signal_events; se; se = sn) {
 		sn = se->next;
 		se->event_ctx = NULL;
@@ -350,6 +358,47 @@ struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
 }
 
 /*
+  allocate an immediate event
+  return NULL on failure (memory allocation error)
+*/
+struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
+						  const char *location)
+{
+	struct tevent_immediate *im;
+
+	im = talloc(mem_ctx, struct tevent_immediate);
+	if (im == NULL) return NULL;
+
+	im->prev		= NULL;
+	im->next		= NULL;
+	im->event_ctx		= NULL;
+	im->create_location	= location;
+	im->handler		= NULL;
+	im->private_data	= NULL;
+	im->handler_name	= NULL;
+	im->schedule_location	= NULL;
+	im->cancel_fn		= NULL;
+	im->additional_data	= NULL;
+
+	return im;
+}
+
+/*
+  schedule an immediate event
+  return NULL on failure
+*/
+void _tevent_schedule_immediate(struct tevent_immediate *im,
+				struct tevent_context *ev,
+				tevent_immediate_handler_t handler,
+				void *private_data,
+				const char *handler_name,
+				const char *location)
+{
+	ev->ops->schedule_immediate(im, ev, handler, private_data,
+				    handler_name, location);
+}
+
+/*
   add a signal event
 
   sa_flags are flags to sigaction(2)
@@ -514,6 +563,34 @@ done:
 /*
   return on failure or (with 0) if all fd events are removed
 */
+int tevent_common_loop_wait(struct tevent_context *ev,
+			    const char *location)
+{
+	/*
+	 * loop as long as we have events pending
+	 */
+	while (ev->fd_events ||
+	       ev->timer_events ||
+	       ev->immediate_events ||
+	       ev->signal_events) {
+		int ret;
+		ret = _tevent_loop_once(ev, location);
+		if (ret != 0) {
+			tevent_debug(ev, TEVENT_DEBUG_FATAL,
+				     "_tevent_loop_once() failed: %d - %s\n",
+				     ret, strerror(errno));
+			return ret;
+		}
+	}
+
+	tevent_debug(ev, TEVENT_DEBUG_WARNING,
+		     "tevent_common_loop_wait() out of events\n");
+	return 0;
+}
+
+/*
+  return on failure or (with 0) if all fd events are removed
+*/
 int _tevent_loop_wait(struct tevent_context *ev, const char *location)
 {
 	return ev->ops->loop_wait(ev, location);
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 4a3f51a..6c5df63 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -37,6 +37,7 @@ struct tevent_context;
 struct tevent_ops;
 struct tevent_fd;
 struct tevent_timer;
+struct tevent_immediate;
 struct tevent_signal;
 
 /* event handler types */
@@ -52,6 +53,9 @@ typedef void (*tevent_timer_handler_t)(struct tevent_context *ev,
 				       struct tevent_timer *te,
 				       struct timeval current_time,
 				       void *private_data);
+typedef void (*tevent_immediate_handler_t)(struct tevent_context *ctx,
+					   struct tevent_immediate *im,
+					   void *private_data);
 typedef void (*tevent_signal_handler_t)(struct tevent_context *ev,
 					struct tevent_signal *se,
 					int signum,
@@ -87,6 +91,21 @@ struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
 	_tevent_add_timer(ev, mem_ctx, next_event, handler, private_data, \
 			  #handler, __location__)
 
+struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx,
+						  const char *location);
+#define tevent_create_immediate(mem_ctx) \
+	_tevent_create_immediate(mem_ctx, __location__)
+
+void _tevent_schedule_immediate(struct tevent_immediate *im,
+				struct tevent_context *ctx,
+				tevent_immediate_handler_t handler,
+				void *private_data,
+				const char *handler_name,
+				const char *location);
+#define tevent_schedule_immediate(im, ctx, handler, private_data) \
+	_tevent_schedule_immediate(im, ctx, handler, private_data, \
+				   #handler, __location__);
+
 struct tevent_signal *_tevent_add_signal(struct tevent_context *ev,
 					 TALLOC_CTX *mem_ctx,
 					 int signum,
@@ -233,13 +252,22 @@ bool tevent_req_set_endtime(struct tevent_req *req,
 			    struct tevent_context *ev,
 			    struct timeval endtime);
 
-void tevent_req_done(struct tevent_req *req);
+void _tevent_req_done(struct tevent_req *req,
+		      const char *location);
+#define tevent_req_done(req) \
+	_tevent_req_done(req, __location__)
 
-bool tevent_req_error(struct tevent_req *req,
-		      uint64_t error);
+bool _tevent_req_error(struct tevent_req *req,
+		       uint64_t error,
+		       const char *location);
+#define tevent_req_error(req, error) \
+	_tevent_req_error(req, error, __location__)
 
-bool tevent_req_nomem(const void *p,
-		      struct tevent_req *req);
+bool _tevent_req_nomem(const void *p,
+		       struct tevent_req *req,
+		       const char *location);
+#define tevent_req_nomem(p, req) \
+	_tevent_req_nomem(p, req, __location__)
 
 struct tevent_req *tevent_req_post(struct tevent_req *req,
 				   struct tevent_context *ev);
@@ -295,8 +323,7 @@ bool tevent_queue_add(struct tevent_queue *queue,
 		      struct tevent_req *req,
 		      tevent_queue_trigger_fn_t trigger,
 		      void *private_data);
-bool tevent_queue_start(struct tevent_queue *queue,
-			struct tevent_context *ev);
+void tevent_queue_start(struct tevent_queue *queue);
 void tevent_queue_stop(struct tevent_queue *queue);
 
 size_t tevent_queue_length(struct tevent_queue *queue);
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index b63d299..7c7f389 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -35,14 +35,6 @@ struct epoll_event_context {
 	/* a pointer back to the generic event_context */
 	struct tevent_context *ev;
 
-	/* this is changed by the destructors for the fd event
-	   type. It is used to detect event destruction by event
-	   handlers, which means the code that is calling the event
-	   handler needs to assume that the linked list is no longer
-	   valid
-	*/
-	uint32_t destruction_count;
-
 	/* when using epoll this is the handle from epoll_create */
 	int epoll_fd;
 
@@ -242,9 +234,8 @@ static void epoll_change_event(struct epoll_event_context *epoll_ev, struct teve
 static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval *tvalp)
 {
 	int ret, i;
-#define MAXEVENTS 32
+#define MAXEVENTS 1
 	struct epoll_event events[MAXEVENTS];
-	uint32_t destruction_count = ++epoll_ev->destruction_count;
 	int timeout = -1;
 
 	if (epoll_ev->epoll_fd == -1) return -1;
@@ -305,9 +296,7 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval
 		if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE;
 		if (flags) {
 			fde->handler(epoll_ev->ev, fde, flags, fde->private_data);
-			if (destruction_count != epoll_ev->destruction_count) {
-				break;
-			}
+			break;
 		}
 	}
 
@@ -351,8 +340,6 @@ static int epoll_event_fd_destructor(struct tevent_fd *fde)
 
 		epoll_check_reopen(epoll_ev);
 
-		epoll_ev->destruction_count++;
-
 		epoll_del_event(epoll_ev, fde);
 	}
 
@@ -417,6 +404,16 @@ static int epoll_event_loop_once(struct tevent_context *ev, const char *location
 		 					   struct epoll_event_context);
 	struct timeval tval;
 
+	if (ev->signal_events &&
+	    tevent_common_check_signal(ev)) {
+		return 0;
+	}
+
+	if (ev->immediate_events &&
+	    tevent_common_loop_immediate(ev)) {
+		return 0;
+	}
+
 	tval = tevent_common_loop_timer_delay(ev);
 	if (tevent_timeval_is_zero(&tval)) {
 		return 0;
@@ -427,32 +424,17 @@ static int epoll_event_loop_once(struct tevent_context *ev, const char *location
 	return epoll_event_loop(epoll_ev, &tval);
 }
 
-/*
-  return on failure or (with 0) if all fd events are removed
-*/
-static int epoll_event_loop_wait(struct tevent_context *ev, const char *location)
-{
-	struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data,
-							   struct epoll_event_context);
-	while (epoll_ev->ev->fd_events) {
-		if (epoll_event_loop_once(ev, location) != 0) {
-			break;
-		}
-	}
-
-	return 0;
-}
-
 static const struct tevent_ops epoll_event_ops = {
-	.context_init	= epoll_event_context_init,
-	.add_fd		= epoll_event_add_fd,
-	.set_fd_close_fn= tevent_common_fd_set_close_fn,
-	.get_fd_flags	= tevent_common_fd_get_flags,
-	.set_fd_flags	= epoll_event_set_fd_flags,
-	.add_timer	= tevent_common_add_timer,
-	.add_signal	= tevent_common_add_signal,
-	.loop_once	= epoll_event_loop_once,
-	.loop_wait	= epoll_event_loop_wait,
+	.context_init		= epoll_event_context_init,
+	.add_fd			= epoll_event_add_fd,
+	.set_fd_close_fn	= tevent_common_fd_set_close_fn,
+	.get_fd_flags		= tevent_common_fd_get_flags,
+	.set_fd_flags		= epoll_event_set_fd_flags,
+	.add_timer		= tevent_common_add_timer,
+	.schedule_immediate	= tevent_common_schedule_immediate,
+	.add_signal		= tevent_common_add_signal,
+	.loop_once		= epoll_event_loop_once,
+	.loop_wait		= tevent_common_loop_wait,
 };
 
 bool tevent_epoll_init(void)
diff --git a/lib/tevent/tevent_immediate.c b/lib/tevent/tevent_immediate.c
new file mode 100644
index 0000000..1ac293e
--- /dev/null
+++ b/lib/tevent/tevent_immediate.c
@@ -0,0 +1,139 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   common events code for immediate events
+
+   Copyright (C) Stefan Metzmacher 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
+   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/>.
+*/
+
+#include "replace.h"
+#include "tevent.h"
+#include "tevent_internal.h"
+#include "tevent_util.h"
+
+static void tevent_common_immediate_cancel(struct tevent_immediate *im)
+{
+	if (!im->event_ctx) {
+		return;
+	}
+
+	tevent_debug(im->event_ctx, TEVENT_DEBUG_TRACE,
+		     "Cancel immediate event %p \"%s\"\n",
+		     im, im->handler_name);
+
+	/* let the backend free im->additional_data */
+	if (im->cancel_fn) {
+		im->cancel_fn(im);
+	}
+
+	DLIST_REMOVE(im->event_ctx->immediate_events, im);
+	im->event_ctx		= NULL;
+	im->handler		= NULL;
+	im->private_data	= NULL;
+	im->handler_name	= NULL;
+	im->schedule_location	= NULL;
+	im->cancel_fn		= NULL;
+	im->additional_data	= NULL;
+
+	talloc_set_destructor(im, NULL);
+}
+
+/*
+  destroy an immediate event
+*/
+static int tevent_common_immediate_destructor(struct tevent_immediate *im)
+{
+	tevent_common_immediate_cancel(im);
+	return 0;
+}
+
+/*
+ * schedule an immediate event on
+ */
+void tevent_common_schedule_immediate(struct tevent_immediate *im,
+				      struct tevent_context *ev,
+				      tevent_immediate_handler_t handler,
+				      void *private_data,
+				      const char *handler_name,
+				      const char *location)
+{
+	tevent_common_immediate_cancel(im);
+
+	if (!handler) {
+		return;
+	}
+
+	im->event_ctx		= ev;
+	im->handler		= handler;
+	im->private_data	= private_data;
+	im->handler_name	= handler_name;
+	im->schedule_location	= location;
+	im->cancel_fn		= NULL;
+	im->additional_data	= NULL;
+
+	DLIST_ADD_END(ev->immediate_events, im, struct tevent_immediate *);
+	talloc_set_destructor(im, tevent_common_immediate_destructor);
+
+	tevent_debug(ev, TEVENT_DEBUG_TRACE,
+		     "Schedule immediate event \"%s\": %p\n",
+		     handler_name, im);
+}
+
+/*
+  trigger the first immediate event and return true
+  if no event was triggered return false
+*/
+bool tevent_common_loop_immediate(struct tevent_context *ev)
+{
+	struct tevent_immediate *im = ev->immediate_events;
+	tevent_immediate_handler_t handler;
+	void *private_data;
+
+	if (!im) {
+		return false;
+	}
+
+	tevent_debug(ev, TEVENT_DEBUG_TRACE,
+		     "Run immediate event \"%s\": %p\n",
+		     im->handler_name, im);
+
+	/*
+	 * remember the handler and then clear the event
+	 * the handler might reschedule the event
+	 */
+	handler = im->handler;
+	private_data = im->private_data;
+
+	DLIST_REMOVE(im->event_ctx->immediate_events, im);
+	im->event_ctx		= NULL;
+	im->handler		= NULL;
+	im->private_data	= NULL;
+	im->handler_name	= NULL;
+	im->schedule_location	= NULL;
+	im->cancel_fn		= NULL;
+	im->additional_data	= NULL;
+
+	talloc_set_destructor(im, NULL);
+
+	handler(ev, im, private_data);
+
+	return true;
+}
+
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index f104853..eebf767 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -85,7 +85,17 @@ struct tevent_req {
 		 *
 		 * This for debugging only.
 		 */
-		const char *location;
+		const char *create_location;
+
+		/**
+		 * @brief The location where the request was finished
+		 *
+		 * This uses the __location__ macro via the tevent_req_done(),
+		 * tevent_req_error() or tevent_req_nomem() macro.
+		 *
+		 * This for debugging only.
+		 */
+		const char *finish_location;
 
 		/**
 		 * @brief The external state - will be queried by the caller
@@ -105,10 +115,10 @@ struct tevent_req {
 		uint64_t error;
 
 		/**
-		 * @brief the timer event if tevent_req_post was used
+		 * @brief the immediate event used by tevent_req_post


-- 
Samba Shared Repository


More information about the samba-cvs mailing list