r4936: moved to a convention where the completion function is only called in
authorAndrew Tridgell <tridge@samba.org>
Sun, 23 Jan 2005 08:16:16 +0000 (08:16 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:07 +0000 (13:09 -0500)
one place. This makes the code more robust, and simpler (it would have
prevented the error that volker found).
(This used to be commit 420b53091ee784d7891fb62d48e2f5a225b4dbf8)

source4/libcli/composite/loadfile.c
source4/libcli/composite/savefile.c

index 37327ca62e37b7ac29b0e405f0d602c9217e0145..37f3608a4b96c9a0617a13c09b22e5ba2e2c3076 100644 (file)
@@ -170,9 +170,6 @@ static NTSTATUS loadfile_close(struct smbcli_composite *c,
        NT_STATUS_NOT_OK_RETURN(status);
        
        c->state = SMBCLI_REQUEST_DONE;
-       if (c->async.fn) {
-               c->async.fn(c);
-       }
 
        return NT_STATUS_OK;
 }
@@ -185,30 +182,30 @@ static void loadfile_handler(struct smbcli_request *req)
 {
        struct smbcli_composite *c = req->async.private;
        struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state);
-       NTSTATUS status;
 
        /* when this handler is called, the stage indicates what
           call has just finished */
        switch (state->stage) {
        case LOADFILE_OPEN:
-               status = loadfile_open(c, state->io);
+               c->status = loadfile_open(c, state->io);
                break;
 
        case LOADFILE_READ:
-               status = loadfile_read(c, state->io);
+               c->status = loadfile_read(c, state->io);
                break;
 
        case LOADFILE_CLOSE:
-               status = loadfile_close(c, state->io);
+               c->status = loadfile_close(c, state->io);
                break;
        }
 
-       if (!NT_STATUS_IS_OK(status)) {
-               c->status = status;
+       if (!NT_STATUS_IS_OK(c->status)) {
                c->state = SMBCLI_REQUEST_ERROR;
-               if (c->async.fn) {
-                       c->async.fn(c);
-               }
+       }
+
+       if (c->state >= SMBCLI_REQUEST_DONE &&
+           c->async.fn) {
+               c->async.fn(c);
        }
 }
 
index c87ea178f9db3fba4401e055362d94f4033c820d..5da56601270059bd14b46a9979c7160dace541e7 100644 (file)
@@ -171,9 +171,6 @@ static NTSTATUS savefile_close(struct smbcli_composite *c,
        }
        
        c->state = SMBCLI_REQUEST_DONE;
-       if (c->async.fn) {
-               c->async.fn(c);
-       }
 
        return NT_STATUS_OK;
 }
@@ -186,30 +183,30 @@ static void savefile_handler(struct smbcli_request *req)
 {
        struct smbcli_composite *c = req->async.private;
        struct savefile_state *state = talloc_get_type(c->private, struct savefile_state);
-       NTSTATUS status;
 
        /* when this handler is called, the stage indicates what
           call has just finished */
        switch (state->stage) {
        case SAVEFILE_OPEN:
-               status = savefile_open(c, state->io);
+               c->status = savefile_open(c, state->io);
                break;
 
        case SAVEFILE_WRITE:
-               status = savefile_write(c, state->io);
+               c->status = savefile_write(c, state->io);
                break;
 
        case SAVEFILE_CLOSE:
-               status = savefile_close(c, state->io);
+               c->status = savefile_close(c, state->io);
                break;
        }
 
-       if (!NT_STATUS_IS_OK(status)) {
-               c->status = status;
+       if (!NT_STATUS_IS_OK(c->status)) {
                c->state = SMBCLI_REQUEST_ERROR;
-               if (c->async.fn) {
-                       c->async.fn(c);
-               }
+       }
+
+       if (c->state >= SMBCLI_REQUEST_DONE &&
+           c->async.fn) {
+               c->async.fn(c);
        }
 }