From: Martin Ling Date: Wed, 27 Nov 2013 12:42:27 +0000 (+0000) Subject: Handle EINTR by repeating the call. X-Git-Tag: libserialport-0.1.0~35 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=63a17c64ae5222a218600ecb4d9f320a91e74cc9;p=libserialport.git Handle EINTR by repeating the call. --- diff --git a/serialport.c b/serialport.c index 0a467de..51eda87 100644 --- a/serialport.c +++ b/serialport.c @@ -890,9 +890,14 @@ enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t c timersub(&end, &now, &delta); } result = select(port->fd + 1, NULL, &fds, NULL, timeout ? &delta : NULL); - if (result < 0) - RETURN_FAIL("select() failed"); - if (result == 0) { + if (result < 0) { + if (errno == EINTR) { + DEBUG("select() call was interrupted, repeating"); + continue; + } else { + RETURN_FAIL("select() failed"); + } + } else if (result == 0) { DEBUG("write timed out"); RETURN_VALUE("%d", bytes_written); } @@ -1060,9 +1065,14 @@ enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, u timersub(&end, &now, &delta); } result = select(port->fd + 1, &fds, NULL, NULL, timeout ? &delta : NULL); - if (result < 0) - RETURN_FAIL("select() failed"); - if (result == 0) { + if (result < 0) { + if (errno == EINTR) { + DEBUG("select() call was interrupted, repeating"); + continue; + } else { + RETURN_FAIL("select() failed"); + } + } else if (result == 0) { DEBUG("read timed out"); RETURN_VALUE("%d", bytes_read); }