summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-02-25 12:35:48 +0100
committerVolker Lendecke <vl@samba.org>2009-02-25 13:04:18 +0100
commitd1c7bbd893c27ebff28571b4ea611bd3e35148c1 (patch)
treeb2b755643c36f1dbf6de2a97631d75db33c04af3 /source3
parent258ae4cec596631b758fb17c170c4494e4db8a8e (diff)
downloadsamba-d1c7bbd893c27ebff28571b4ea611bd3e35148c1.tar.gz
samba-d1c7bbd893c27ebff28571b4ea611bd3e35148c1.tar.bz2
samba-d1c7bbd893c27ebff28571b4ea611bd3e35148c1.zip
Convert rpc_sock_read to use tevent_req base async_read
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_client/rpc_transport_sock.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/source3/rpc_client/rpc_transport_sock.c b/source3/rpc_client/rpc_transport_sock.c
index c0fa41b0de..68421b3b4c 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,22 +48,53 @@ 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;
+ }
+ subreq->async.fn = rpc_sock_read_done;
+ subreq->async.private_data = 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 = talloc_get_type_abort(
+ subreq->async.private_data, 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;
}