r14161: return early if we know the job is already finished
authorSimo Sorce <idra@samba.org>
Fri, 10 Mar 2006 15:27:16 +0000 (15:27 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:56:56 +0000 (13:56 -0500)
(This used to be commit 09f6f552d73f782dc8d62cefad9c5f584b7b07d2)

source4/lib/ldb/ldb_ildap/ldb_ildap.c
source4/lib/ldb/ldb_ldap/ldb_ldap.c
source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
source4/lib/ldb/ldb_tdb/ldb_tdb.c

index f309262a551cd36e74a8c020f59e47faf04a163e..ceb9c4aafb9017fa65d8f7398172436bab8996d5 100644 (file)
@@ -352,6 +352,9 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg
 
        h->private_data = (void *)ildb_ac;
 
+       h->state = LDB_ASYNC_INIT;
+       h->status = LDB_SUCCESS;
+
        req = ldap_request_send(ildb->ldap, msg);
        if (req == NULL) {
                ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed"));
@@ -922,6 +925,10 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
 {
        struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context);
 
+       if (handle->state == LDB_ASYNC_DONE) {
+               return handle->status;
+       }
+
        if (!ac) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
index 5a4d9112187d0f1560b50fdb78fc760809fd258a..a2ca7a7cc8cceedce2bf264d2490cc630ce24b39 100644 (file)
@@ -87,6 +87,9 @@ static struct ldb_async_handle *init_handle(struct lldb_private *lldb, struct ld
 
        h->private_data = (void *)ac;
 
+       h->state = LDB_ASYNC_INIT;
+       h->status = LDB_SUCCESS;
+
        ac->module = module;
        ac->context = context;
        ac->callback = callback;
@@ -885,12 +888,15 @@ static int lldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
        LDAPMessage *result;
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
-       if (!ac->msgid) {
+       if (handle->state == LDB_ASYNC_DONE) {
+               return handle->status;
+       }
+
+       if (!ac || !ac->msgid) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
        handle->status = LDB_SUCCESS;
-       handle->state = LDB_ASYNC_INIT;
 
        switch(type) {
        case LDB_WAIT_NONE:
index d9d9269de4a58900965d0a7da4f6e0a7ceb260a3..bcb830c38d496bfd8c585252e4b4e872b18ab42e 100644 (file)
@@ -57,9 +57,9 @@ struct lsql_async_context {
        int (*callback)(struct ldb_context *, void *, struct ldb_async_result *);
 };
 
-static struct ldb_async_handle *init_lsql_handle(struct lsqlite3_private *lsqlite3, struct ldb_module *module,
-                                                void *context,
-                                                int (*callback)(struct ldb_context *, void *, struct ldb_async_result *))
+static struct ldb_async_handle *init_handle(struct lsqlite3_private *lsqlite3, struct ldb_module *module,
+                                           void *context,
+                                           int (*callback)(struct ldb_context *, void *, struct ldb_async_result *))
 {
        struct lsql_async_context *ac;
        struct ldb_async_handle *h;
@@ -81,6 +81,9 @@ static struct ldb_async_handle *init_lsql_handle(struct lsqlite3_private *lsqlit
 
        h->private_data = (void *)ac;
 
+       h->state = LDB_ASYNC_INIT;
+       h->status = LDB_SUCCESS;
+
        ac->module = module;
        ac->context = context;
        ac->callback = callback;
@@ -899,7 +902,7 @@ int lsql_search_async(struct ldb_module *module, const struct ldb_dn *base,
        char *query = NULL;
         int ret;
 
-       *handle = init_lsql_handle(lsqlite3, module, context, callback);
+       *handle = init_handle(lsqlite3, module, context, callback);
        if (*handle == NULL) {
                talloc_free(*handle);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -1111,7 +1114,7 @@ static int lsql_add_async(struct ldb_module *module, struct ldb_message *msg,
        int i;
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
-       *handle = init_lsql_handle(lsqlite3, module, context, callback);
+       *handle = init_handle(lsqlite3, module, context, callback);
        if (*handle == NULL) {
                goto failed;
        }
@@ -1267,7 +1270,7 @@ static int lsql_modify_async(struct ldb_module *module, const struct ldb_message
        int i;
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
-       *handle = init_lsql_handle(lsqlite3, module, context, callback);
+       *handle = init_handle(lsqlite3, module, context, callback);
        if (*handle == NULL) {
                goto failed;
        }
@@ -1481,7 +1484,7 @@ static int lsql_delete_async(struct ldb_module *module, const struct ldb_dn *dn,
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
 
-       *handle = init_lsql_handle(lsqlite3, module, context, callback);
+       *handle = init_handle(lsqlite3, module, context, callback);
        if (*handle == NULL) {
                goto failed;
        }
@@ -1559,7 +1562,7 @@ static int lsql_rename_async(struct ldb_module *module, const struct ldb_dn *old
        char *query;
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
-       *handle = init_lsql_handle(lsqlite3, module, context, callback);
+       *handle = init_handle(lsqlite3, module, context, callback);
        if (*handle == NULL) {
                goto failed;
        }
index a77553dcb8c8f9ace17ba46c4322688ce98e18d9..bc936eb71e49a6b23363954d6872b5adf0d6679b 100644 (file)
@@ -102,6 +102,9 @@ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_
 
        h->private_data = (void *)ac;
 
+       h->state = LDB_ASYNC_INIT;
+       h->status = LDB_SUCCESS;
+
        ac->module = module;
        ac->context = context;
        ac->callback = callback;