Author: tridge Date: 2004-09-02 12:03:16 +0000 (Thu, 02 Sep 2004) New Revision: 2185
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2185&nolog=1 Log: add a callback function to the dcerpc async API also add a demonstration of its use in the netlogon async example Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c branches/SAMBA_4_0/source/librpc/rpc/dcerpc.h branches/SAMBA_4_0/source/torture/rpc/netlogon.c Changeset: Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c =================================================================== --- branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c 2004-09-02 12:02:28 UTC (rev 2184) +++ branches/SAMBA_4_0/source/librpc/rpc/dcerpc.c 2004-09-02 12:03:16 UTC (rev 2185) @@ -631,6 +631,9 @@ req->state = RPC_REQUEST_DONE; req->status = status; DLIST_REMOVE(p->pending, req); + if (req->async.callback) { + req->async.callback(req); + } } return; } @@ -655,6 +658,9 @@ req->status = status; req->state = RPC_REQUEST_DONE; DLIST_REMOVE(p->pending, req); + if (req->async.callback) { + req->async.callback(req); + } return; } @@ -664,6 +670,9 @@ req->status = NT_STATUS_NET_WRITE_FAULT; req->state = RPC_REQUEST_DONE; DLIST_REMOVE(p->pending, req); + if (req->async.callback) { + req->async.callback(req); + } return; } @@ -674,6 +683,9 @@ req->status = NT_STATUS_NET_WRITE_FAULT; req->state = RPC_REQUEST_DONE; DLIST_REMOVE(p->pending, req); + if (req->async.callback) { + req->async.callback(req); + } return; } @@ -686,6 +698,9 @@ req->status = NT_STATUS_NO_MEMORY; req->state = RPC_REQUEST_DONE; DLIST_REMOVE(p->pending, req); + if (req->async.callback) { + req->async.callback(req); + } return; } memcpy(req->payload.data+req->payload.length, @@ -707,6 +722,10 @@ } else { req->flags &= ~DCERPC_PULL_BIGENDIAN; } + + if (req->async.callback) { + req->async.callback(req); + } } @@ -737,6 +756,7 @@ req->payload = data_blob(NULL, 0); req->flags = 0; req->fault_code = 0; + req->async.callback = NULL; init_dcerpc_hdr(p, &pkt); Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc.h =================================================================== --- branches/SAMBA_4_0/source/librpc/rpc/dcerpc.h 2004-09-02 12:02:28 UTC (rev 2184) +++ branches/SAMBA_4_0/source/librpc/rpc/dcerpc.h 2004-09-02 12:03:16 UTC (rev 2185) @@ -166,4 +166,9 @@ size_t struct_size; TALLOC_CTX *mem_ctx; } ndr; + + struct { + void (*callback)(struct rpc_request *); + void *private; + } async; }; Modified: branches/SAMBA_4_0/source/torture/rpc/netlogon.c =================================================================== --- branches/SAMBA_4_0/source/torture/rpc/netlogon.c 2004-09-02 12:02:28 UTC (rev 2184) +++ branches/SAMBA_4_0/source/torture/rpc/netlogon.c 2004-09-02 12:03:16 UTC (rev 2185) @@ -1625,6 +1625,14 @@ } +static void async_callback(struct rpc_request *req) +{ + int *counter = req->async.private; + if (NT_STATUS_IS_OK(req->status)) { + (*counter)++; + } +} + static BOOL test_GetDomainInfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx) { NTSTATUS status; @@ -1636,6 +1644,7 @@ struct creds_CredentialState creds_async[ASYNC_COUNT]; struct rpc_request *req[ASYNC_COUNT]; int i; + int async_counter = 0; if (!test_SetupCredentials3(p, mem_ctx, NETLOGON_NEG_AUTH2_ADS_FLAGS, &creds)) { return False; @@ -1670,6 +1679,13 @@ creds_async[i] = creds; req[i] = dcerpc_netr_LogonGetDomainInfo_send(p, mem_ctx, &r); + + req[i]->async.callback = async_callback; + req[i]->async.private = &async_counter; + + /* even with this flush per request a w2k3 server seems to + clag with multiple outstanding requests. bleergh. */ + event_loop_once(dcerpc_event_context(p)); } for (i=0;i<ASYNC_COUNT;i++) { @@ -1677,18 +1693,18 @@ if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(r.out.result)) { printf("netr_LogonGetDomainInfo_async(%d) - %s/%s\n", i, nt_errstr(status), nt_errstr(r.out.result)); - return False; + break; } if (!creds_client_check(&creds_async[i], &a.cred)) { printf("Credential chaining failed at async %d\n", i); - return False; + break; } } - printf("Testing netr_LogonGetDomainInfo - async count %d OK\n", ASYNC_COUNT); + printf("Testing netr_LogonGetDomainInfo - async count %d OK\n", async_counter); - return True; + return async_counter == ASYNC_COUNT; }