svn commit: samba r12087 - in branches/SAMBA_4_0/source/librpc/rpc: .

tridge at samba.org tridge at samba.org
Tue Dec 6 12:56:00 GMT 2005


Here is a patch that implements the automatic composite trigger on
composite_error() and composite_done().

Metze and Volker, as you've both worked on this code, any holes you
can see?


Index: libcli/composite/composite.c
===================================================================
--- libcli/composite/composite.c	(revision 12085)
+++ libcli/composite/composite.c	(working copy)
@@ -35,6 +35,8 @@
 {
 	if (c == NULL) return NT_STATUS_NO_MEMORY;
 
+	c->used_wait = True;
+
 	while (c->state < COMPOSITE_STATE_DONE) {
 		if (event_loop_once(c->event_ctx) != 0) {
 			return NT_STATUS_UNSUCCESSFUL;
@@ -46,7 +48,7 @@
 
 
 /* 
-   callback from composite_trigger_done() and composite_trigger_error()
+   callback from composite_done() and composite_error()
 */
 static void composite_trigger(struct event_context *ev, struct timed_event *te,
 			      struct timeval t, void *ptr)
@@ -59,26 +61,6 @@
 
 
 /*
-  trigger an immediate 'done' event on a composite context
-  this is used when the composite code works out that the call
-  can be completed without waiting for any external event
-*/
-void composite_trigger_done(struct composite_context *c)
-{
-	c->state = COMPOSITE_STATE_DONE;
-	/* a zero timeout means immediate */
-	event_add_timed(c->event_ctx, c, timeval_zero(), composite_trigger, c);
-}
-
-void composite_trigger_error(struct composite_context *c)
-{
-	c->state = COMPOSITE_STATE_ERROR;
-	/* a zero timeout means immediate */
-	event_add_timed(c->event_ctx, c, timeval_zero(), composite_trigger, c);
-}
-
-
-/*
  * Some composite helpers that are handy if you write larger composite
  * functions.
  */
@@ -97,6 +79,9 @@
 
 void composite_error(struct composite_context *ctx, NTSTATUS status)
 {
+	if (!ctx->used_wait && !ctx->async.fn) {
+		event_add_timed(ctx->event_ctx, ctx, timeval_zero(), composite_trigger, ctx);
+	}
 	ctx->status = status;
 	SMB_ASSERT(!composite_is_ok(ctx));
 }
@@ -112,6 +97,9 @@
 
 void composite_done(struct composite_context *ctx)
 {
+	if (!ctx->used_wait && !ctx->async.fn) {
+		event_add_timed(ctx->event_ctx, ctx, timeval_zero(), composite_trigger, ctx);
+	}
 	ctx->state = COMPOSITE_STATE_DONE;
 	if (ctx->async.fn != NULL) {
 		ctx->async.fn(ctx);
Index: winbind/wb_sid2domain.c
===================================================================
--- winbind/wb_sid2domain.c	(revision 12085)
+++ winbind/wb_sid2domain.c	(working copy)
@@ -85,7 +85,7 @@
 	state->domain = find_domain_from_sid(service, sid);
 	if (state->domain != NULL) {
 		result->status = NT_STATUS_OK;
-		composite_trigger_done(result);
+		composite_done(result);
 		return result;
 	}
 
Index: winbind/wb_async_helpers.c
===================================================================
--- winbind/wb_async_helpers.c	(revision 12085)
+++ winbind/wb_async_helpers.c	(working copy)
@@ -230,7 +230,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
Index: lib/socket/connect_multi.c
===================================================================
--- lib/socket/connect_multi.c	(revision 12085)
+++ lib/socket/connect_multi.c	(working copy)
@@ -119,7 +119,7 @@
 	return result;
 
  failed:
-	composite_trigger_error(result);
+	composite_error(result, result->status);
 	return result;
 }
 
Index: lib/socket/connect.c
===================================================================
--- lib/socket/connect.c	(revision 12085)
+++ lib/socket/connect.c	(working copy)
@@ -138,7 +138,7 @@
 	return result;
 
 failed:
-	composite_trigger_error(result);
+	composite_error(result, result->status);
 	return result;
 }
 
Index: wrepl_server/wrepl_out_helpers.c
===================================================================
--- wrepl_server/wrepl_out_helpers.c	(revision 12085)
+++ wrepl_server/wrepl_out_helpers.c	(working copy)
@@ -156,12 +156,12 @@
 		if (!wreplconn->sock->dead) {
 			state->stage	= WREPLSRV_OUT_CONNECT_STAGE_DONE;
 			state->wreplconn= wreplconn;
-			composite_trigger_done(c);
+			composite_done(c);
 			return c;
 		} else if (!cached_connection) {
 			state->stage	= WREPLSRV_OUT_CONNECT_STAGE_DONE;
 			state->wreplconn= NULL;
-			composite_trigger_done(c);
+			composite_done(c);
 			return c;
 		} else {
 			talloc_free(wreplconn);
@@ -328,7 +328,7 @@
 		state->table_io.out.num_partners	= io->in.num_owners;
 		state->table_io.out.partners		= io->in.owners;
 		state->stage				= WREPLSRV_PULL_TABLE_STAGE_DONE;
-		composite_trigger_done(c);
+		composite_done(c);
 		return c;
 	}
 
Index: libcli/resolve/resolve.c
===================================================================
--- libcli/resolve/resolve.c	(revision 12085)
+++ libcli/resolve/resolve.c	(working copy)
@@ -153,7 +153,7 @@
 		struct ipv4_addr ip = interpret_addr2(state->name.name);
 		state->reply_addr = talloc_strdup(state, sys_inet_ntoa(ip));
 		if (!state->reply_addr) goto failed;
-		composite_trigger_done(c);
+		composite_done(c);
 		return c;
 	}
 
Index: libcli/ldap/ldap_client.c
===================================================================
--- libcli/ldap/ldap_client.c	(revision 12085)
+++ libcli/ldap/ldap_client.c	(working copy)
@@ -341,7 +341,7 @@
 	state->ctx->status = ldap_parse_basic_url(conn, url, &conn->host,
 						  &conn->port, &conn->ldaps);
 	if (!NT_STATUS_IS_OK(state->ctx->status)) {
-		composite_trigger_error(state->ctx);
+		composite_error(state->ctx, state->ctx->status);
 		return result;
 	}
 
Index: libcli/composite/composite.h
===================================================================
--- libcli/composite/composite.h	(revision 12085)
+++ libcli/composite/composite.h	(working copy)
@@ -57,4 +57,6 @@
 		void (*fn)(struct composite_context *);
 		void *private_data;
 	} async;
+
+	BOOL used_wait;
 };
Index: libcli/smb2/session.c
===================================================================
--- libcli/smb2/session.c	(revision 12085)
+++ libcli/smb2/session.c	(working copy)
@@ -253,7 +253,7 @@
 	return c;
 
 failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
Index: libcli/smb2/connect.c
===================================================================
--- libcli/smb2/connect.c	(revision 12085)
+++ libcli/smb2/connect.c	(working copy)
@@ -201,7 +201,7 @@
 	return c;
 
 failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
Index: torture/rpc/xplogin.c
===================================================================
--- torture/rpc/xplogin.c	(revision 12085)
+++ torture/rpc/xplogin.c	(working copy)
@@ -373,7 +373,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -475,7 +475,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -655,7 +655,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -898,7 +898,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -1109,7 +1109,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -1420,7 +1420,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -1550,7 +1550,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -1689,7 +1689,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
Index: librpc/rpc/dcerpc.c
===================================================================
--- librpc/rpc/dcerpc.c	(revision 12085)
+++ librpc/rpc/dcerpc.c	(working copy)
@@ -722,7 +722,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
@@ -1633,7 +1633,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }
 
Index: librpc/rpc/dcerpc_auth.c
===================================================================
--- librpc/rpc/dcerpc_auth.c	(revision 12085)
+++ librpc/rpc/dcerpc_auth.c	(working copy)
@@ -47,7 +47,7 @@
 	if (!NT_STATUS_IS_OK(c->status)) {
 		DEBUG(2,("Invalid uuid string in "
 			 "dcerpc_bind_auth_none_send\n"));
-		composite_trigger_error(c);
+		composite_error(c, c->status);
 		return c;
 	}
 
@@ -277,7 +277,7 @@
 		NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED);
 
 	if (state->credentials.length == 0) {
-		composite_trigger_done(c);
+		composite_done(c);
 		return c;
 	}
 
@@ -296,7 +296,7 @@
 	return c;
 
  failed:
-	composite_trigger_error(c);
+	composite_error(c, c->status);
 	return c;
 }


More information about the samba-technical mailing list