client: handle the case of zero data bytes

When terminating the connection, we might get a read of zero

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-07-29 09:42:42 +10:00
parent fb115a1f43
commit 23c34fc77d
2 changed files with 9 additions and 5 deletions

View file

@ -401,10 +401,14 @@ client_dispatch(struct source *source, void *data)
_cleanup_iobuf_ struct iobuf *buf = iobuf_new(64);
int rc = iobuf_append_from_fd(buf, source_get_fd(source));
if (rc == -EAGAIN)
if (rc == -EAGAIN) {
return;
else if (rc < 0)
} else if (rc == 0) {
rc = -ECANCELED;
goto error;
} else if (rc < 0) {
goto error;
}
msg = client_parse_message(iobuf_data(buf), iobuf_len(buf));
if (!msg) {

View file

@ -127,9 +127,9 @@ iobuf_append_from_fd(struct iobuf *buf, int fd)
ssize_t rc;
do {
rc = xread(fd, data, sizeof(data));
if (rc <= 0) {
if (rc == -EAGAIN)
return nread;
if (rc == 0 || rc == -EAGAIN) {
break;
} else if (rc < 0) {
return rc;
}