Handle EINTR by repeating the call.

This commit is contained in:
Martin Ling 2013-11-27 12:42:27 +00:00
parent 1b34204261
commit 63a17c64ae
1 changed files with 16 additions and 6 deletions

View File

@ -890,9 +890,14 @@ enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t c
timersub(&end, &now, &delta); timersub(&end, &now, &delta);
} }
result = select(port->fd + 1, NULL, &fds, NULL, timeout ? &delta : NULL); result = select(port->fd + 1, NULL, &fds, NULL, timeout ? &delta : NULL);
if (result < 0) if (result < 0) {
if (errno == EINTR) {
DEBUG("select() call was interrupted, repeating");
continue;
} else {
RETURN_FAIL("select() failed"); RETURN_FAIL("select() failed");
if (result == 0) { }
} else if (result == 0) {
DEBUG("write timed out"); DEBUG("write timed out");
RETURN_VALUE("%d", bytes_written); 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); timersub(&end, &now, &delta);
} }
result = select(port->fd + 1, &fds, NULL, NULL, timeout ? &delta : NULL); result = select(port->fd + 1, &fds, NULL, NULL, timeout ? &delta : NULL);
if (result < 0) if (result < 0) {
if (errno == EINTR) {
DEBUG("select() call was interrupted, repeating");
continue;
} else {
RETURN_FAIL("select() failed"); RETURN_FAIL("select() failed");
if (result == 0) { }
} else if (result == 0) {
DEBUG("read timed out"); DEBUG("read timed out");
RETURN_VALUE("%d", bytes_read); RETURN_VALUE("%d", bytes_read);
} }