aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/chelper/serialqueue.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c
index b6500fe6..e6810933 100644
--- a/klippy/chelper/serialqueue.c
+++ b/klippy/chelper/serialqueue.c
@@ -62,6 +62,7 @@ struct serialqueue {
int ready_bytes, upcoming_bytes, need_ack_bytes, last_ack_bytes;
uint64_t need_kick_clock;
struct list_head notify_queue;
+ double last_write_fail_time;
// Received messages
struct list_head receive_queue;
// Fastreader support
@@ -376,8 +377,16 @@ do_write(struct serialqueue *sq, void *buf, int buflen)
int ret = write(sq->serial_fd, &cf, sizeof(cf));
if (ret < 0) {
report_errno("can write", ret);
+ double curtime = get_monotonic();
+ if (!sq->last_write_fail_time) {
+ sq->last_write_fail_time = curtime;
+ } else if (curtime > sq->last_write_fail_time + 10.0) {
+ errorf("Halting reads due to CAN write errors.");
+ pollreactor_do_exit(sq->pr);
+ }
return;
}
+ sq->last_write_fail_time = 0.0;
buf += size;
buflen -= size;
}