diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-03-05 12:24:35 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-03-05 12:24:35 +1100 |
commit | 41760c18bdab20d526d32568531bdf7c88272879 (patch) | |
tree | b2f421919501a3061afe40f0cb0980f86f448ea8 /source3/rpc_client/rpc_transport_sock.c | |
parent | 8249383efb2037bb234dd040ebe151329cc4feb9 (diff) | |
parent | c8ea9d1f13096cd7f51e5972915a61ca65b56ac3 (diff) | |
download | samba-41760c18bdab20d526d32568531bdf7c88272879.tar.gz samba-41760c18bdab20d526d32568531bdf7c88272879.tar.bz2 samba-41760c18bdab20d526d32568531bdf7c88272879.zip |
Merge branch 'master' of ssh://git.samba.org/data/git/samba into wspp-schema
Diffstat (limited to 'source3/rpc_client/rpc_transport_sock.c')
-rw-r--r-- | source3/rpc_client/rpc_transport_sock.c | 108 |
1 files changed, 91 insertions, 17 deletions
diff --git a/source3/rpc_client/rpc_transport_sock.c b/source3/rpc_client/rpc_transport_sock.c index c0fa41b0de..b1d9d8fbe1 100644 --- a/source3/rpc_client/rpc_transport_sock.c +++ b/source3/rpc_client/rpc_transport_sock.c @@ -35,6 +35,12 @@ static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state * return 0; } +struct rpc_sock_read_state { + ssize_t received; +}; + +static void rpc_sock_read_done(struct tevent_req *subreq); + static struct async_req *rpc_sock_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev, uint8_t *data, size_t size, @@ -42,25 +48,61 @@ static struct async_req *rpc_sock_read_send(TALLOC_CTX *mem_ctx, { struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort( priv, struct rpc_transport_sock_state); - return async_recv(mem_ctx, ev, sock_transp->fd, data, size, 0); + struct async_req *result; + struct tevent_req *subreq; + struct rpc_sock_read_state *state; + + if (!async_req_setup(mem_ctx, &result, &state, + struct rpc_sock_read_state)) { + return NULL; + } + + subreq = async_recv_send(state, ev, sock_transp->fd, data, size, 0); + if (subreq == NULL) { + goto fail; + } + tevent_req_set_callback(subreq, rpc_sock_read_done, result); + return result; + fail: + TALLOC_FREE(result); + return NULL; } -static NTSTATUS rpc_sock_read_recv(struct async_req *req, ssize_t *preceived) +static void rpc_sock_read_done(struct tevent_req *subreq) { - ssize_t received; - int sys_errno; + struct async_req *req = + tevent_req_callback_data(subreq, struct async_req); + struct rpc_sock_read_state *state = talloc_get_type_abort( + req->private_data, struct rpc_sock_read_state); + int err; - received = async_syscall_result_ssize_t(req, &sys_errno); - if (received == -1) { - return map_nt_error_from_unix(sys_errno); + state->received = async_recv_recv(subreq, &err); + if (state->received == -1) { + async_req_nterror(req, map_nt_error_from_unix(err)); + return; } - if (received == 0) { - return NT_STATUS_END_OF_FILE; + async_req_done(req); +} + +static NTSTATUS rpc_sock_read_recv(struct async_req *req, ssize_t *preceived) +{ + struct rpc_sock_read_state *state = talloc_get_type_abort( + req->private_data, struct rpc_sock_read_state); + NTSTATUS status; + + if (async_req_is_nterror(req, &status)) { + return status; } - *preceived = received; + *preceived = state->received; return NT_STATUS_OK; } +struct rpc_sock_write_state { + ssize_t sent; +}; + +static void rpc_sock_write_done(struct tevent_req *subreq); + static struct async_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev, const uint8_t *data, size_t size, @@ -68,19 +110,51 @@ static struct async_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx, { struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort( priv, struct rpc_transport_sock_state); - return async_send(mem_ctx, ev, sock_transp->fd, data, size, 0); + struct async_req *result; + struct tevent_req *subreq; + struct rpc_sock_write_state *state; + + if (!async_req_setup(mem_ctx, &result, &state, + struct rpc_sock_write_state)) { + return NULL; + } + subreq = async_send_send(state, ev, sock_transp->fd, data, size, 0); + if (subreq == NULL) { + goto fail; + } + tevent_req_set_callback(subreq, rpc_sock_write_done, result); + return result; + fail: + TALLOC_FREE(result); + return NULL; +} + +static void rpc_sock_write_done(struct tevent_req *subreq) +{ + struct async_req *req = + tevent_req_callback_data(subreq, struct async_req); + struct rpc_sock_write_state *state = talloc_get_type_abort( + req->private_data, struct rpc_sock_write_state); + int err; + + state->sent = async_send_recv(subreq, &err); + if (state->sent == -1) { + async_req_nterror(req, map_nt_error_from_unix(err)); + return; + } + async_req_done(req); } static NTSTATUS rpc_sock_write_recv(struct async_req *req, ssize_t *psent) { - ssize_t sent; - int sys_errno; + struct rpc_sock_write_state *state = talloc_get_type_abort( + req->private_data, struct rpc_sock_write_state); + NTSTATUS status; - sent = async_syscall_result_ssize_t(req, &sys_errno); - if (sent == -1) { - return map_nt_error_from_unix(sys_errno); + if (async_req_is_nterror(req, &status)) { + return status; } - *psent = sent; + *psent = state->sent; return NT_STATUS_OK; } |