mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
Simplify async programming a bit with helper routines
Introduce async_req_is_error() and async_req_simple_recv()
This commit is contained in:
parent
f9aa69ae35
commit
7fbb64d726
@ -134,4 +134,8 @@ bool async_post_status(struct async_req *req, NTSTATUS status);
|
||||
|
||||
bool async_req_nomem(const void *p, struct async_req *req);
|
||||
|
||||
bool async_req_is_error(struct async_req *req, NTSTATUS *status);
|
||||
|
||||
NTSTATUS async_req_simple_recv(struct async_req *req);
|
||||
|
||||
#endif
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -732,12 +732,7 @@ struct async_req *cli_echo_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
|
||||
|
||||
NTSTATUS cli_echo_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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -908,9 +908,8 @@ NTSTATUS cli_open_recv(struct async_req *req, int *fnum)
|
||||
uint8_t *bytes;
|
||||
NTSTATUS status;
|
||||
|
||||
SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
|
||||
if (req->state == ASYNC_REQ_ERROR) {
|
||||
return req->status;
|
||||
if (async_req_is_error(req, &status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
|
||||
@ -985,10 +984,10 @@ NTSTATUS cli_close_recv(struct async_req *req)
|
||||
uint16_t *vwv;
|
||||
uint16_t num_bytes;
|
||||
uint8_t *bytes;
|
||||
NTSTATUS status;
|
||||
|
||||
SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
|
||||
if (req->state == ASYNC_REQ_ERROR) {
|
||||
return req->status;
|
||||
if (async_req_is_error(req, &status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
|
||||
|
@ -112,9 +112,8 @@ NTSTATUS cli_read_andx_recv(struct async_req *req, ssize_t *received,
|
||||
NTSTATUS status;
|
||||
size_t size;
|
||||
|
||||
SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
|
||||
if (req->state == ASYNC_REQ_ERROR) {
|
||||
return req->status;
|
||||
if (async_req_is_error(req, &status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
|
||||
@ -405,10 +404,10 @@ NTSTATUS cli_pull_recv(struct async_req *req, SMB_OFF_T *received)
|
||||
{
|
||||
struct cli_pull_state *state = talloc_get_type_abort(
|
||||
req->private_data, struct cli_pull_state);
|
||||
NTSTATUS status;
|
||||
|
||||
SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
|
||||
if (req->state == ASYNC_REQ_ERROR) {
|
||||
return req->status;
|
||||
if (async_req_is_error(req, &status)) {
|
||||
return status;
|
||||
}
|
||||
*received = state->pushed;
|
||||
return NT_STATUS_OK;
|
||||
|
@ -1316,10 +1316,10 @@ NTSTATUS cli_trans_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
|
||||
req->private_data, struct cli_request);
|
||||
struct cli_trans_state *state = talloc_get_type_abort(
|
||||
cli_req->recv_helper.priv, struct cli_trans_state);
|
||||
NTSTATUS status;
|
||||
|
||||
SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
|
||||
if (req->state == ASYNC_REQ_ERROR) {
|
||||
return req->status;
|
||||
if (async_req_is_error(req, &status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (setup != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user