From ef16fa500ba869a031d1bf94a35af0d81625e035 Mon Sep 17 00:00:00 2001 From: Shivesh Khaitan Date: Mon, 2 Sep 2019 00:23:38 +0530 Subject: [PATCH] Fix is_connected --- src/socket_can.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/socket_can.cpp b/src/socket_can.cpp index d0b7261..25d5a7e 100644 --- a/src/socket_can.cpp +++ b/src/socket_can.cpp @@ -48,6 +48,21 @@ void SocketCAN::init() return; } + int error = 0; + socklen_t len = sizeof (error); + int retval = getsockopt (socket_, SOL_SOCKET, SO_ERROR, &error, &len); + if (retval != 0) { + /* there was a problem getting the error code */ + printf("Error getting socket error code: %s\n", strerror(retval)); + return; + } + + if (error != 0) { + /* socket has a non zero error status */ + printf("Socket error: %s\n", strerror(error)); + return; + } + struct timeval timeout{}; timeout.tv_sec = (timeout_ / 1000); timeout.tv_usec = (timeout_ % 1000) * 1000;