diff options
author | Volker Lendecke <vl@samba.org> | 2009-02-23 08:56:35 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2009-02-24 20:40:48 +0100 |
commit | 25df6d74131b8b9bd8924ca70eb891ff97d3ddfd (patch) | |
tree | 30bf060ed233ae85bbf1196f7f6c18a8195cc762 /lib | |
parent | a60480b71ad7cdaa495b7624f04bc477a3330cbf (diff) | |
download | samba-25df6d74131b8b9bd8924ca70eb891ff97d3ddfd.tar.gz samba-25df6d74131b8b9bd8924ca70eb891ff97d3ddfd.tar.bz2 samba-25df6d74131b8b9bd8924ca70eb891ff97d3ddfd.zip |
Add more conventional async_recv
Diffstat (limited to 'lib')
-rw-r--r-- | lib/async_req/async_sock.c | 67 | ||||
-rw-r--r-- | lib/async_req/async_sock.h | 5 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c index 323d285729..3563421e0e 100644 --- a/lib/async_req/async_sock.c +++ b/lib/async_req/async_sock.c @@ -445,6 +445,73 @@ ssize_t async_send_recv(struct tevent_req *req, int *perrno) return state->sent; } +struct async_recv_state { + int fd; + void *buf; + size_t len; + int flags; + ssize_t received; +}; + +static void async_recv_handler(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, void *private_data); + +struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + int fd, void *buf, size_t len, int flags) +{ + struct tevent_req *result; + struct async_recv_state *state; + struct tevent_fd *fde; + + result = tevent_req_create(mem_ctx, &state, struct async_recv_state); + if (result == NULL) { + return result; + } + state->fd = fd; + state->buf = buf; + state->len = len; + state->flags = flags; + + fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ, async_recv_handler, + result); + if (fde == NULL) { + TALLOC_FREE(result); + return NULL; + } + return result; +} + +static void async_recv_handler(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, void *private_data) +{ + struct tevent_req *req = talloc_get_type_abort( + private_data, struct tevent_req); + struct async_recv_state *state = talloc_get_type_abort( + req->private_state, struct async_recv_state); + + state->received = recv(state->fd, state->buf, state->len, + state->flags); + if (state->received == -1) { + tevent_req_error(req, errno); + return; + } + tevent_req_done(req); +} + +ssize_t async_recv_recv(struct tevent_req *req, int *perrno) +{ + struct async_recv_state *state = talloc_get_type_abort( + req->private_state, struct async_recv_state); + + if (tevent_req_is_unix_error(req, perrno)) { + return -1; + } + return state->received; +} + struct async_connect_state { int fd; int result; diff --git a/lib/async_req/async_sock.h b/lib/async_req/async_sock.h index 89dabdac4c..bfc4346d39 100644 --- a/lib/async_req/async_sock.h +++ b/lib/async_req/async_sock.h @@ -42,6 +42,11 @@ struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx, int flags); ssize_t async_send_recv(struct tevent_req *req, int *perrno); +struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + int fd, void *buf, size_t len, int flags); +ssize_t async_recv_recv(struct tevent_req *req, int *perrno); + struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, const struct sockaddr *address, |