SIGSEGV when removing Ethernet/Serial Port cables

Have a boost enable application which communicated over USB serial ports and UDP If the cables are removed, the library fires off SIGSEGV signals. I am trying to catch exceptions but neither } catch (boost::system::system_error &e) { } catch (std::exception &e) { seems to work, and a SIGSEGV signal is sent when the port->get_io_service().reset(); statement is executed. How can I handle the problem, that the USB serial cable is removed? I know I can test for the existence of /dev/ttyUSBx in the file system or /sys/class/tty/ttyUSBx" I know I can write a SIGSEGV handler, but would like to know if there is any exception I can catch instead. Have the same problem when the Ethernet Cable is removed. How handle this? // Serial Port Read. // Reads a character or times out bool SerialPort::read_char(unsigned char& val) { val = c = '\0'; try { // After a timeout & cancel it seems we need // to do a reset for subsequent reads to work. port->get_io_service().reset(); // Asynchronously read 1 character. async_read(*port, buffer(&c, 1), boost::bind(&SerialPort::read_complete, this, placeholders::error, placeholders::bytes_transferred)); // Setup a deadline time to implement our timeout. timer->expires_from_now(boost::posix_time::milliseconds(1)); timer->async_wait(boost::bind(&SerialPort::time_out, this, placeholders::error)); // This will block until a character is read // or until the it is cancelled. port->get_io_service().run(); if (!read_error) { val = c; } else { val = 0; // Timeout } } catch (boost::system::system_error &e) { val = 2; DebugPort.WriteLine("Serial Port System Error", RED); return false; } catch (std::exception &e) { val = 1; DebugPort.WriteLine("Serial Port General Error", RED); return false; } return !read_error; } // Network port open bool UdpClient::Open(void) { udp::resolver resolver(io_service); udp::resolver::query query(udp::v4(), ipAddress, Port); try { Endpoint = *resolver.resolve(query); } catch (boost::system::system_error &e) { // We might not have a network connection return false; } if (!CreateSocket()) { return false; } if (!OpenSocket()) { return false; } init = true; return true; } Best Regards Ulf Samuelsson

Have a boost enable application which communicated over USB serial ports and UDP
If the cables are removed, the library fires off SIGSEGV signals.
I am trying to catch exceptions but neither } catch (boost::system::system_error &e) { } catch (std::exception &e) { seems to work, and a SIGSEGV signal is sent when the
port->get_io_service().reset();
statement is executed.
If "port" is a raw pointer, check that it points to a valid object. Anyway, segsegv is not translated to c++ exception (although one can do that like this: http://stackoverflow.com/questions/16777362/need-explanation-of-the-usage-of...).
participants (2)
-
Igor R
-
Ulf Samuelsson