From a261e68d0dd32a03fdf42522e6d2c8259ba0f3d1 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 9 May 2017 16:48:49 +0200 Subject: Fix: Avoid returning negative value that's stop watch socket Even if the frame read is wrong doesn't mean that socket is compromise only that communication on CAN bus is difficult, maybe temporary. On en EPOLL err code, or hangup, just close and restart the socket and reset the filter. Change-Id: I61f146fd269bb2524f09e1f2ed89d93e83166136 Signed-off-by: Romain Forlot --- CAN-binder/low-can-binding/binding/low-can-cb.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'CAN-binder/low-can-binding/binding') diff --git a/CAN-binder/low-can-binding/binding/low-can-cb.cpp b/CAN-binder/low-can-binding/binding/low-can-cb.cpp index 414fa91..2183893 100644 --- a/CAN-binder/low-can-binding/binding/low-can-cb.cpp +++ b/CAN-binder/low-can-binding/binding/low-can-cb.cpp @@ -55,9 +55,16 @@ void on_no_clients(std::string message) int read(sd_event_source *s, int fd, uint32_t revents, void *userdata) { can_signal_t* sig= (can_signal_t*)userdata; - if(sig->read_socket() != can_message_format_t::ERROR) - return 0; - return -1; + sig->read_socket(); + + /* check if error or hangup */ + if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0) + { + sd_event_source_unref(s); + sig->get_socket().close(); + sig->create_rx_filter(); + } + return 0; } ///****************************************************************************** -- cgit 1.2.3-korg