struct iovec *iov;
int count;
size_t total_size;
+ uint16_t flags;
};
static void writev_trigger(struct tevent_req *req, void *private_data);
struct tevent_req *writev_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct tevent_queue *queue, int fd,
+ bool err_on_readability,
struct iovec *iov, int count)
{
struct tevent_req *req;
if (state->iov == NULL) {
goto fail;
}
+ state->flags = TEVENT_FD_WRITE;
+ if (err_on_readability) {
+ state->flags |= TEVENT_FD_READ;
+ }
if (queue == NULL) {
struct tevent_fd *fde;
fde = tevent_add_fd(state->ev, state, state->fd,
- TEVENT_FD_WRITE, writev_handler, req);
+ state->flags, writev_handler, req);
if (tevent_req_nomem(fde, req)) {
return tevent_req_post(req, ev);
}
struct writev_state *state = tevent_req_data(req, struct writev_state);
struct tevent_fd *fde;
- fde = tevent_add_fd(state->ev, state, state->fd, TEVENT_FD_WRITE,
+ fde = tevent_add_fd(state->ev, state, state->fd, state->flags,
writev_handler, req);
if (fde == NULL) {
tevent_req_error(req, ENOMEM);
to_write = 0;
+ if (flags & TEVENT_FD_READ) {
+ tevent_req_error(req, EPIPE);
+ return;
+ }
+
for (i=0; i<state->count; i++) {
to_write += state->iov[i].iov_len;
}
struct tevent_req *writev_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct tevent_queue *queue, int fd,
+ bool err_on_readability,
struct iovec *iov, int count);
ssize_t writev_recv(struct tevent_req *req, int *perrno);
count = 2;
}
- subreq = writev_send(state, ev, queue, fd, state->iov, count);
+ subreq = writev_send(state, ev, queue, fd, true, state->iov, count);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
count = 2;
}
- subreq = writev_send(state, ev, queue, fd, state->iov, count);
+ subreq = writev_send(state, ev, queue, fd, true, state->iov, count);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
iov[0].iov_base = (void *)buf;
iov[0].iov_len = talloc_get_size(buf);
subreq = writev_send(state, state->ev, state->cli->outgoing,
- state->cli->fd, iov, 1);
+ state->cli->fd, false, iov, 1);
} else {
subreq = writev_send(state, state->ev, state->cli->outgoing,
- state->cli->fd, iov, iov_count);
+ state->cli->fd, false, iov, iov_count);
}
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
state->iov.iov_len = len;
subreq = writev_send(state, ev, p->write_queue, p->fd,
- &state->iov, 1);
+ false, &state->iov, 1);
if (subreq == NULL) {
goto fail;
}