From 34376be9559943aa33108f7b4af462df0b914cc6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 7 Mar 2012 04:59:28 +0000 Subject: after select(), if both ioctl() and read() return a 0 count, assume that we lost the connection and close the serial port svn path=/trunk/externals/iem/comport/; revision=16051 --- comport/comport.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'comport') diff --git a/comport/comport.c b/comport/comport.c index 814a95e..06390c2 100644 --- a/comport/comport.c +++ b/comport/comport.c @@ -1078,7 +1078,18 @@ static void comport_tick(t_comport *x) outlet_float(x->x_data_outlet, (t_float) x->x_inbuf[i]); } } - else whicherr = errno; + else if (err == 0 && count == 0) + { + /* if both ioctl() and read() return a 0 count, assume + * that we lost the connection to the serial port. + * otherwise there is a race condition when the serial + * port gets interrupted, like if the USB gets yanked + * out or a bluetooth connection drops */ + pd_error(x, "Lost connection to serial device, closing!"); + comport_close(x); + } + else + whicherr = errno; } #endif /* _WIN32 */ if(err < 0) -- cgit v1.2.1