summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-01-18 16:38:30 +0100
committerVolker Lendecke <vl@samba.org>2009-01-18 16:45:07 +0100
commit0dbd3968626445b4dcb00307e45206b37dd0e8ad (patch)
tree79ffe7396e8af5c52593509df3877c545970d2b3 /source3/lib
parentc45b6ec29a5b3a39b83209e970b645e5ed0a411c (diff)
downloadsamba-0dbd3968626445b4dcb00307e45206b37dd0e8ad.tar.gz
samba-0dbd3968626445b4dcb00307e45206b37dd0e8ad.tar.bz2
samba-0dbd3968626445b4dcb00307e45206b37dd0e8ad.zip
Add a macro async_req_setup()
This streamlines setting up a multi-step async request a bit
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/async_req.c25
-rw-r--r--source3/lib/async_sock.c20
-rw-r--r--source3/lib/util_sock.c20
-rw-r--r--source3/lib/wb_reqtrans.c44
-rw-r--r--source3/lib/wbclient.c29
5 files changed, 47 insertions, 91 deletions
diff --git a/source3/lib/async_req.c b/source3/lib/async_req.c
index 13b64ba79a..011948a158 100644
--- a/source3/lib/async_req.c
+++ b/source3/lib/async_req.c
@@ -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;
+}
diff --git a/source3/lib/async_sock.c b/source3/lib/async_sock.c
index bb89a1353a..73ff6f2870 100644
--- a/source3/lib/async_sock.c
+++ b/source3/lib/async_sock.c
@@ -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) {
- return NULL;
- }
-
- state = talloc(result, struct async_syscall_state);
- if (state == NULL) {
- TALLOC_FREE(result);
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct async_syscall_state)) {
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
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 98c25c1e24..3ddc4342a7 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -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;
diff --git a/source3/lib/wb_reqtrans.c b/source3/lib/wb_reqtrans.c
index 1f5f181aa1..0e6e5d15c4 100644
--- a/source3/lib/wb_reqtrans.c
+++ b/source3/lib/wb_reqtrans.c
@@ -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;
diff --git a/source3/lib/wbclient.c b/source3/lib/wbclient.c
index d58c934c07..ea0bcb512e 100644
--- a/source3/lib/wbclient.c
+++ b/source3/lib/wbclient.c
@@ -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);