diff options
author | Stefan Metzmacher <metze@samba.org> | 2022-10-13 16:23:03 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2022-10-19 16:14:36 +0000 |
commit | 4c7e2b9b60de5d02bb3f69effe7eddbf466a6155 (patch) | |
tree | c24b647bdf8652a1fc8df0f4d8ecb5b949f39366 /lib/tsocket | |
parent | 29a65da63d730ecead1e7d4a81a76dd1c8c179ea (diff) | |
download | samba-4c7e2b9b60de5d02bb3f69effe7eddbf466a6155.tar.gz |
lib/tsocket: remember the first error as tstream_bsd->error
If we found that the connection is broken, there's no point
in trying to use it anymore, so just return the first error we detected.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/tsocket')
-rw-r--r-- | lib/tsocket/tsocket_bsd.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 8ab2ffb0b83..72499561f2d 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -1744,6 +1744,7 @@ int _tdgram_unix_socket(const struct tsocket_address *local, struct tstream_bsd { int fd; + int error; void *event_ptr; struct tevent_fd *fde; @@ -1921,7 +1922,19 @@ static ssize_t tstream_bsd_pending_bytes(struct tstream_context *stream) return -1; } + if (bsds->error != 0) { + errno = bsds->error; + return -1; + } + ret = tsocket_bsd_pending(bsds->fd); + if (ret == -1) { + /* + * remember the error and don't + * allow further requests + */ + bsds->error = errno; + } return ret; } @@ -2029,9 +2042,15 @@ static void tstream_bsd_readv_handler(void *private_data) int _count; bool ok, retry; + if (bsds->error != 0) { + tevent_req_error(req, bsds->error); + return; + } + ret = readv(bsds->fd, state->vector, state->count); if (ret == 0) { /* propagate end of file */ + bsds->error = EPIPE; tevent_req_error(req, EPIPE); return; } @@ -2040,6 +2059,13 @@ static void tstream_bsd_readv_handler(void *private_data) /* retry later */ return; } + if (err != 0) { + /* + * remember the error and don't + * allow further requests + */ + bsds->error = err; + } if (tevent_req_error(req, err)) { return; } @@ -2172,9 +2198,15 @@ static void tstream_bsd_writev_handler(void *private_data) int _count; bool ok, retry; + if (bsds->error != 0) { + tevent_req_error(req, bsds->error); + return; + } + ret = writev(bsds->fd, state->vector, state->count); if (ret == 0) { /* propagate end of file */ + bsds->error = EPIPE; tevent_req_error(req, EPIPE); return; } @@ -2183,6 +2215,13 @@ static void tstream_bsd_writev_handler(void *private_data) /* retry later */ return; } + if (err != 0) { + /* + * remember the error and don't + * allow further requests + */ + bsds->error = err; + } if (tevent_req_error(req, err)) { return; } |