1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

posix: Consistent debug output when blocking operations time out.

This commit is contained in:
Martin Ling 2015-05-07 09:41:41 +01:00 committed by Uwe Hermann
parent 772c586133
commit c3cee38c3b

View File

@ -795,10 +795,9 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
/* Wait until space is available. */ /* Wait until space is available. */
if (timeout_ms) { if (timeout_ms) {
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (timercmp(&now, &end, >)) { if (timercmp(&now, &end, >))
DEBUG("Write timed out"); /* Timeout has expired. */
RETURN_INT(bytes_written); break;
}
timersub(&end, &now, &delta); timersub(&end, &now, &delta);
} }
result = select(port->fd + 1, NULL, &fds, NULL, timeout_ms ? &delta : NULL); result = select(port->fd + 1, NULL, &fds, NULL, timeout_ms ? &delta : NULL);
@ -810,8 +809,8 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
RETURN_FAIL("select() failed"); RETURN_FAIL("select() failed");
} }
} else if (result == 0) { } else if (result == 0) {
DEBUG("Write timed out"); /* Timeout has expired. */
RETURN_INT(bytes_written); break;
} }
/* Do write. */ /* Do write. */
@ -830,6 +829,9 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
ptr += result; ptr += result;
} }
if (bytes_written < count)
DEBUG("Write timed out");
RETURN_INT(bytes_written); RETURN_INT(bytes_written);
#endif #endif
} }
@ -1013,7 +1015,7 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (timercmp(&now, &end, >)) if (timercmp(&now, &end, >))
/* Timeout has expired. */ /* Timeout has expired. */
RETURN_INT(bytes_read); break;
timersub(&end, &now, &delta); timersub(&end, &now, &delta);
} }
result = select(port->fd + 1, &fds, NULL, NULL, timeout_ms ? &delta : NULL); result = select(port->fd + 1, &fds, NULL, NULL, timeout_ms ? &delta : NULL);
@ -1025,8 +1027,8 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
RETURN_FAIL("select() failed"); RETURN_FAIL("select() failed");
} }
} else if (result == 0) { } else if (result == 0) {
DEBUG("Read timed out"); /* Timeout has expired. */
RETURN_INT(bytes_read); break;
} }
/* Do read. */ /* Do read. */
@ -1045,6 +1047,9 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
ptr += result; ptr += result;
} }
if (bytes_read < count)
DEBUG("Read timed out");
RETURN_INT(bytes_read); RETURN_INT(bytes_read);
#endif #endif
} }