1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

Add a macro async_req_setup()

This streamlines setting up a multi-step async request a bit
This commit is contained in:
Volker Lendecke 2009-01-18 16:38:30 +01:00
parent c45b6ec29a
commit 0dbd396862
8 changed files with 77 additions and 176 deletions

View File

@ -150,4 +150,11 @@ bool async_req_enqueue(struct async_req_queue *queue,
struct async_req *req,
void (*trigger)(struct async_req *req));
bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
void *pstate, size_t state_size, const char *typename);
#define async_req_setup(_mem_ctx, _preq, _pstate, type) \
_async_req_setup((_mem_ctx), (_preq), (_pstate), sizeof(type), #type)
#endif

View File

@ -313,3 +313,28 @@ bool async_req_enqueue(struct async_req_queue *queue, struct event_context *ev,
return true;
}
bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
void *pstate, size_t state_size, const char *typename)
{
struct async_req *req;
void **ppstate = (void **)pstate;
void *state;
req = async_req_new(mem_ctx);
if (req == NULL) {
return false;
}
state = talloc_size(req, state_size);
if (state == NULL) {
TALLOC_FREE(req);
return false;
}
talloc_set_name(state, typename);
req->private_data = state;
*preq = req;
*ppstate = state;
return true;
}

View File

@ -106,17 +106,10 @@ static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
struct async_req *result;
struct async_syscall_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct async_syscall_state)) {
return NULL;
}
state = talloc(result, struct async_syscall_state);
if (state == NULL) {
TALLOC_FREE(result);
return NULL;
}
state->syscall_type = type;
result->private_data = state;
@ -569,15 +562,10 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
struct fd_event *fde;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct async_connect_state)) {
return NULL;
}
state = talloc(result, struct async_connect_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
/**
* We have to set the socket to nonblocking for async connect(2). Keep

View File

@ -978,16 +978,10 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
struct open_socket_out_state *state;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct open_socket_out_state)) {
return NULL;
}
state = talloc(result, struct open_socket_out_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->ss = *pss;
state->port = port;
@ -1170,16 +1164,10 @@ struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
struct open_socket_out_defer_state *state;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct open_socket_out_defer_state)) {
return NULL;
}
state = talloc(result, struct open_socket_out_defer_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->ss = *pss;
state->port = port;

View File

@ -43,17 +43,10 @@ struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct req_read_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct req_read_state)) {
return NULL;
}
state = talloc(result, struct req_read_state);
if (state == NULL) {
goto nomem;
}
result->private_data = state;
state->fd = fd;
state->ev = ev;
state->max_extra_data = max_extra_data;
@ -205,17 +198,10 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct req_write_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct req_write_state)) {
return NULL;
}
state = talloc(result, struct req_write_state);
if (state == NULL) {
goto nomem;
}
result->private_data = state;
state->fd = fd;
state->ev = ev;
state->wb_req = wb_req;
@ -304,17 +290,10 @@ struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct resp_read_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct resp_read_state)) {
return NULL;
}
state = talloc(result, struct resp_read_state);
if (state == NULL) {
goto nomem;
}
result->private_data = state;
state->fd = fd;
state->ev = ev;
state->wb_resp = talloc(state, struct winbindd_response);
@ -458,17 +437,10 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct resp_write_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct resp_write_state)) {
return NULL;
}
state = talloc(result, struct resp_write_state);
if (state == NULL) {
goto nomem;
}
result->private_data = state;
state->fd = fd;
state->ev = ev;
state->wb_resp = wb_resp;

View File

@ -289,15 +289,10 @@ static struct async_req *wb_int_trans_send(TALLOC_CTX *mem_ctx,
struct async_req *subreq;
struct wb_int_trans_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct wb_int_trans_state)) {
return NULL;
}
state = talloc(result, struct wb_int_trans_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
if (winbind_closed_fd(fd)) {
if (!async_post_status(result, ev,
@ -420,16 +415,10 @@ static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx,
struct async_req *subreq;
struct wb_open_pipe_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct wb_open_pipe_state)) {
return NULL;
}
state = talloc(result, struct wb_open_pipe_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->wb_ctx = wb_ctx;
state->ev = ev;
state->need_priv = need_priv;
@ -617,16 +606,10 @@ struct async_req *wb_trans_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
struct async_req *result;
struct wb_trans_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct wb_trans_state)) {
return NULL;
}
state = talloc(result, struct wb_trans_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->wb_ctx = wb_ctx;
state->ev = ev;
state->wb_req = winbindd_request_copy(state, wb_req);

View File

@ -278,15 +278,10 @@ struct async_req *cli_pull_send(TALLOC_CTX *mem_ctx,
struct cli_pull_state *state;
int i;
result = async_req_new(mem_ctx);
if (result == NULL) {
goto failed;
if (!async_req_setup(mem_ctx, &result, &state,
struct cli_pull_state)) {
return NULL;
}
state = talloc(result, struct cli_pull_state);
if (state == NULL) {
goto failed;
}
result->private_data = state;
result->print = cli_pull_print;
state->req = result;
@ -843,16 +838,10 @@ static struct async_req *cli_writeall_send(TALLOC_CTX *mem_ctx,
struct async_req *subreq;
struct cli_writeall_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
goto fail;
if (!async_req_setup(mem_ctx, &result, &state,
struct cli_writeall_state)) {
return NULL;
}
state = talloc(result, struct cli_writeall_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->fnum = fnum;
@ -969,15 +958,10 @@ struct async_req *cli_push_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
struct cli_push_state *state;
int i;
result = async_req_new(mem_ctx);
if (result == NULL) {
goto failed;
if (!async_req_setup(mem_ctx, &result, &state,
struct cli_push_state)) {
return NULL;
}
state = talloc(result, struct cli_push_state);
if (state == NULL) {
goto failed;
}
result->private_data = state;
state->req = result;
state->cli = cli;

View File

@ -222,16 +222,10 @@ static struct async_req *rpc_read_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct rpc_read_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct rpc_read_state)) {
return NULL;
}
state = talloc(result, struct rpc_read_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->data = data;
@ -361,16 +355,10 @@ static struct async_req *rpc_write_send(TALLOC_CTX *mem_ctx,
struct async_req *result, *subreq;
struct rpc_write_state *state;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct rpc_write_state)) {
return NULL;
}
state = talloc(result, struct rpc_write_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->data = data;
@ -523,16 +511,10 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
uint32_t pdu_len;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct get_complete_frag_state)) {
return NULL;
}
state = talloc(result, struct get_complete_frag_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->prhdr = prhdr;
@ -586,7 +568,6 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
fail:
TALLOC_FREE(result);
return NULL;
}
@ -1165,16 +1146,10 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
struct cli_api_pipe_state *state;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct cli_api_pipe_state)) {
return NULL;
}
state = talloc(result, struct cli_api_pipe_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->max_rdata_len = max_rdata_len;
@ -1227,7 +1202,6 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
fail:
TALLOC_FREE(result);
return NULL;
}
@ -1370,16 +1344,10 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
uint16_t max_recv_frag;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct rpc_api_pipe_state)) {
return NULL;
}
state = talloc(result, struct rpc_api_pipe_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->expected_pkt_type = expected_pkt_type;
@ -1423,7 +1391,6 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
fail:
TALLOC_FREE(result);
return NULL;
}
@ -2184,16 +2151,10 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
NTSTATUS status;
bool is_last_frag;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct rpc_api_pipe_req_state)) {
return NULL;
}
state = talloc(result, struct rpc_api_pipe_req_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
state->ev = ev;
state->cli = cli;
state->op_num = op_num;
@ -2250,7 +2211,6 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
fail:
TALLOC_FREE(result);
return NULL;
}
@ -2667,15 +2627,10 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
struct rpc_pipe_bind_state *state;
NTSTATUS status;
result = async_req_new(mem_ctx);
if (result == NULL) {
if (!async_req_setup(mem_ctx, &result, &state,
struct rpc_pipe_bind_state)) {
return NULL;
}
state = talloc(result, struct rpc_pipe_bind_state);
if (state == NULL) {
goto fail;
}
result->private_data = state;
DEBUG(5,("Bind RPC Pipe: %s auth_type %u, auth_level %u\n",
rpccli_pipe_txt(debug_ctx(), cli),
@ -2717,7 +2672,6 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
fail:
TALLOC_FREE(result);
return NULL;
}