diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2012-03-07 04:59:28 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2012-03-07 04:59:28 +0000 |
commit | 34376be9559943aa33108f7b4af462df0b914cc6 (patch) | |
tree | cb05c50ab6703f0fbfd56a850761f11cc8f7d5b8 /comport | |
parent | b1717b4f7768dc809182f558fd66d53298aa3ff0 (diff) |
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
Diffstat (limited to 'comport')
-rw-r--r-- | comport/comport.c | 13 |
1 files changed, 12 insertions, 1 deletions
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) |