ei: if sending a message fails, don't send any more

Any error will cause ei_disconnect() which in turn unwinds our context.
Each object removed will cause an ei_send_message() to notify the server
but that will only cause error messages - our socket is already gone.

Fix this by removing the source and checking if the fd is still valid
before we write to it.

Fixes #47
This commit is contained in:
Peter Hutterer 2023-10-11 10:21:56 +10:00
parent 3f768ecbfc
commit 38244b8c66

View file

@ -836,15 +836,18 @@ ei_send_message(struct ei *ei, const struct brei_object *object,
_cleanup_iobuf_ struct iobuf *buf = brei_result_get_data(result);
assert(buf);
int fd = source_get_fd(ei->source);
int rc = ei_unsent_flush(ei);
if (rc >= 0)
rc = iobuf_send(buf, fd);
if (rc == -EAGAIN) {
ei_queue_unsent(ei, ei->source, steal(&buf));
rc = 0;
} else if (rc < 0){
log_warn(ei, "failed to send message: %s", strerror(-rc));
int rc = -EPIPE;
if (fd != -1) {
rc = ei_unsent_flush(ei);
if (rc >= 0)
rc = iobuf_send(buf, fd);
if (rc == -EAGAIN) {
ei_queue_unsent(ei, ei->source, steal(&buf));
rc = 0;
} else if (rc < 0){
log_warn(ei, "failed to send message: %s", strerror(-rc));
source_remove(ei->source);
}
}
return rc < 0 ? rc : 0;
}