mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
Streamline the async_sock API a bit
This commit is contained in:
parent
ed25c6c287
commit
f9aa69ae35
@ -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
|
||||
|
@ -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);
|
||||
req->private_data, struct async_syscall_state);
|
||||
|
||||
int sys_errno = state->sys_errno;
|
||||
ssize_t result = state->result.result_ssize_t;
|
||||
|
||||
TALLOC_FREE(*req);
|
||||
|
||||
*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);
|
||||
req->private_data, struct async_syscall_state);
|
||||
|
||||
int sys_errno = state->sys_errno;
|
||||
size_t result = state->result.result_ssize_t;
|
||||
|
||||
TALLOC_FREE(*req);
|
||||
|
||||
*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);
|
||||
req->private_data, struct async_syscall_state);
|
||||
|
||||
int sys_errno = state->sys_errno;
|
||||
int result = state->result.result_ssize_t;
|
||||
|
||||
TALLOC_FREE(*req);
|
||||
|
||||
*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
|
||||
|
Loading…
Reference in New Issue
Block a user