diff options
author | Volker Lendecke <vl@samba.org> | 2008-11-28 19:52:52 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-12-08 22:09:33 +0100 |
commit | f9aa69ae352f7f441b04976575b96ecc8b844dbd (patch) | |
tree | 7a5265125e20ccac19a3aa89c8c0ca1cba328d44 /source3 | |
parent | ed25c6c287ca4f5d019d5f0012b1ff40d5e8e328 (diff) | |
download | samba-f9aa69ae352f7f441b04976575b96ecc8b844dbd.tar.gz samba-f9aa69ae352f7f441b04976575b96ecc8b844dbd.tar.bz2 samba-f9aa69ae352f7f441b04976575b96ecc8b844dbd.zip |
Streamline the async_sock API a bit
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/async_sock.h | 22 | ||||
-rw-r--r-- | source3/lib/async_sock.c | 69 |
2 files changed, 49 insertions, 42 deletions
diff --git a/source3/include/async_sock.h b/source3/include/async_sock.h index 3c90453601..f0cd5fdaa4 100644 --- a/source3/include/async_sock.h +++ b/source3/include/async_sock.h @@ -22,24 +22,28 @@ #include "includes.h" -ssize_t async_syscall_result_ssize_t(struct async_req **req, int *perrno); -size_t async_syscall_result_size_t (struct async_req **req, int *perrno); -ssize_t async_syscall_result_int (struct async_req **req, int *perrno); +ssize_t async_syscall_result_ssize_t(struct async_req *req, int *perrno); +size_t async_syscall_result_size_t(struct async_req *req, int *perrno); +ssize_t async_syscall_result_int(struct async_req *req, int *perrno); struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev, int fd, const void *buffer, size_t length, int flags); -struct async_req *async_sendall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, const void *buffer, size_t length, - int flags); struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev, int fd, void *buffer, size_t length, int flags); -struct async_req *async_recvall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, void *buffer, size_t length, - int flags); struct async_req *async_connect(TALLOC_CTX *mem_ctx, struct event_context *ev, int fd, const struct sockaddr *address, socklen_t address_len); +struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + int fd, const void *buffer, size_t length, + int flags); +NTSTATUS sendall_recv(struct async_req *req); + +struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + int fd, void *buffer, size_t length, + int flags); +NTSTATUS recvall_recv(struct async_req *req); + #endif diff --git a/source3/lib/async_sock.c b/source3/lib/async_sock.c index ffba6de832..ba860e8e78 100644 --- a/source3/lib/async_sock.c +++ b/source3/lib/async_sock.c @@ -177,18 +177,13 @@ static struct async_req *async_fde_syscall_new( * @retval The return value from the asynchronously called syscall */ -ssize_t async_syscall_result_ssize_t(struct async_req **req, int *perrno) +ssize_t async_syscall_result_ssize_t(struct async_req *req, int *perrno) { struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - ssize_t result = state->result.result_ssize_t; - - TALLOC_FREE(*req); + req->private_data, struct async_syscall_state); - *perrno = sys_errno; - return result; + *perrno = state->sys_errno; + return state->result.result_ssize_t; } /** @@ -198,18 +193,13 @@ ssize_t async_syscall_result_ssize_t(struct async_req **req, int *perrno) * @retval The return value from the asynchronously called syscall */ -size_t async_syscall_result_size_t(struct async_req **req, int *perrno) +size_t async_syscall_result_size_t(struct async_req *req, int *perrno) { struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - size_t result = state->result.result_ssize_t; - - TALLOC_FREE(*req); + req->private_data, struct async_syscall_state); - *perrno = sys_errno; - return result; + *perrno = state->sys_errno; + return state->result.result_size_t; } /** @@ -219,18 +209,13 @@ size_t async_syscall_result_size_t(struct async_req **req, int *perrno) * @retval The return value from the asynchronously called syscall */ -ssize_t async_syscall_result_int(struct async_req **req, int *perrno) +ssize_t async_syscall_result_int(struct async_req *req, int *perrno) { struct async_syscall_state *state = talloc_get_type_abort( - (*req)->private_data, struct async_syscall_state); - - int sys_errno = state->sys_errno; - int result = state->result.result_ssize_t; - - TALLOC_FREE(*req); + req->private_data, struct async_syscall_state); - *perrno = sys_errno; - return result; + *perrno = state->sys_errno; + return state->result.result_int; } /** @@ -353,9 +338,9 @@ static void async_sendall_callback(struct event_context *ev, * "length" bytes */ -struct async_req *async_sendall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, const void *buffer, size_t length, - int flags) +struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + int fd, const void *buffer, size_t length, + int flags) { struct async_req *result; struct async_syscall_state *state; @@ -377,6 +362,15 @@ struct async_req *async_sendall(TALLOC_CTX *mem_ctx, struct event_context *ev, return result; } +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; +} + /** * fde event handler for the "recv" syscall * @param[in] ev The event context that sent us here @@ -498,9 +492,9 @@ static void async_recvall_callback(struct event_context *ev, * async_recvall will call recv(2) until "length" bytes are received */ -struct async_req *async_recvall(TALLOC_CTX *mem_ctx, struct event_context *ev, - int fd, void *buffer, size_t length, - int flags) +struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + int fd, void *buffer, size_t length, + int flags) { struct async_req *result; struct async_syscall_state *state; @@ -522,6 +516,15 @@ struct async_req *async_recvall(TALLOC_CTX *mem_ctx, struct event_context *ev, return result; } +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; +} + /** * fde event handler for connect(2) * @param[in] ev The event context that sent us here |