From 7fbb64d726f23da49cd2f07e1a678ed575b70bfa Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 1 Dec 2008 08:23:35 +0100 Subject: Simplify async programming a bit with helper routines Introduce async_req_is_error() and async_req_simple_recv() --- source3/lib/async_req.c | 23 +++++++++++++++++++++++ source3/lib/async_sock.c | 12 ++---------- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/async_req.c b/source3/lib/async_req.c index 501a6b5524..159666f15c 100644 --- a/source3/lib/async_req.c +++ b/source3/lib/async_req.c @@ -172,3 +172,26 @@ bool async_req_nomem(const void *p, struct async_req *req) async_req_error(req, NT_STATUS_NO_MEMORY); return true; } + +bool async_req_is_error(struct async_req *req, NTSTATUS *status) +{ + if (req->state < ASYNC_REQ_DONE) { + *status = NT_STATUS_INTERNAL_ERROR; + return true; + } + if (req->state == ASYNC_REQ_ERROR) { + *status = req->status; + return true; + } + return false; +} + +NTSTATUS async_req_simple_recv(struct async_req *req) +{ + NTSTATUS status; + + if (async_req_is_error(req, &status)) { + return status; + } + return NT_STATUS_OK; +} diff --git a/source3/lib/async_sock.c b/source3/lib/async_sock.c index ba860e8e78..225cc7b195 100644 --- a/source3/lib/async_sock.c +++ b/source3/lib/async_sock.c @@ -364,11 +364,7 @@ struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, NTSTATUS sendall_recv(struct async_req *req) { - SMB_ASSERT(req->state >= ASYNC_REQ_DONE); - if (req->state == ASYNC_REQ_ERROR) { - return req->status; - } - return NT_STATUS_OK; + return async_req_simple_recv(req); } /** @@ -518,11 +514,7 @@ struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, NTSTATUS recvall_recv(struct async_req *req) { - SMB_ASSERT(req->state >= ASYNC_REQ_DONE); - if (req->state == ASYNC_REQ_ERROR) { - return req->status; - } - return NT_STATUS_OK; + return async_req_simple_recv(req); } /** -- cgit