smbXcli: add smb2cli_req_set_notify_async()
authorStefan Metzmacher <metze@samba.org>
Thu, 27 Oct 2011 15:20:27 +0000 (17:20 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 24 Nov 2011 18:02:31 +0000 (19:02 +0100)
That can be used if the caller wants to be notified if
the async interim response arrives.

metze

libcli/smb/smbXcli_base.c
libcli/smb/smbXcli_base.h

index 17256ea6fd406930ee0239d1bed068772eadeb98..a2c94b37401d6a6852b809558235f6ccf1ce21df 100644 (file)
@@ -193,6 +193,8 @@ struct smbXcli_req_state {
                uint16_t credit_charge;
 
                bool signing_skipped;
+               bool notify_async;
+               bool got_async;
        } smb2;
 };
 
@@ -2235,6 +2237,15 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
        return req;
 }
 
+void smb2cli_req_set_notify_async(struct tevent_req *req)
+{
+       struct smbXcli_req_state *state =
+               tevent_req_data(req,
+               struct smbXcli_req_state);
+
+       state->smb2.notify_async = true;
+}
+
 static void smb2cli_writev_done(struct tevent_req *subreq);
 static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
                                               TALLOC_CTX *tmp_mem,
@@ -2634,6 +2645,8 @@ static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
                }
                state = tevent_req_data(req, struct smbXcli_req_state);
 
+               state->smb2.got_async = false;
+
                req_opcode = SVAL(state->smb2.hdr, SMB2_HDR_OPCODE);
                if (opcode != req_opcode) {
                        return NT_STATUS_INVALID_NETWORK_RESPONSE;
@@ -2657,6 +2670,12 @@ static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
                        req_flags |= SMB2_HDR_FLAG_ASYNC;
                        SBVAL(state->smb2.hdr, SMB2_HDR_FLAGS, req_flags);
                        SBVAL(state->smb2.hdr, SMB2_HDR_ASYNC_ID, async_id);
+
+                       if (state->smb2.notify_async) {
+                               state->smb2.got_async = true;
+                               tevent_req_defer_callback(req, state->ev);
+                               tevent_req_notify_callback(req);
+                       }
                        continue;
                }
 
@@ -2833,6 +2852,10 @@ NTSTATUS smb2cli_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                *piov = NULL;
        }
 
+       if (state->smb2.got_async) {
+               return STATUS_PENDING;
+       }
+
        if (tevent_req_is_nterror(req, &status)) {
                for (i=0; i < num_expected; i++) {
                        if (NT_STATUS_EQUAL(status, expected[i].status)) {
index ea03c4caf7564df8c67c3f602980fdf193da43da..543621392b6b5251df438a2623d1cdbbcc6d9e21 100644 (file)
@@ -154,6 +154,7 @@ struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
                                      uint16_t fixed_len,
                                      const uint8_t *dyn,
                                      uint32_t dyn_len);
+void smb2cli_req_set_notify_async(struct tevent_req *req);
 NTSTATUS smb2cli_req_compound_submit(struct tevent_req **reqs,
                                     int num_reqs);
 void smb2cli_req_set_credit_charge(struct tevent_req *req, uint16_t charge);