/* Wait until space is available. */
if (timeout_ms) {
gettimeofday(&now, NULL);
- if (timercmp(&now, &end, >)) {
- DEBUG("Write timed out");
- RETURN_INT(bytes_written);
- }
+ if (timercmp(&now, &end, >))
+ /* Timeout has expired. */
+ break;
timersub(&end, &now, &delta);
}
result = select(port->fd + 1, NULL, &fds, NULL, timeout_ms ? &delta : NULL);
RETURN_FAIL("select() failed");
}
} else if (result == 0) {
- DEBUG("Write timed out");
- RETURN_INT(bytes_written);
+ /* Timeout has expired. */
+ break;
}
/* Do write. */
ptr += result;
}
+ if (bytes_written < count)
+ DEBUG("Write timed out");
+
RETURN_INT(bytes_written);
#endif
}
gettimeofday(&now, NULL);
if (timercmp(&now, &end, >))
/* Timeout has expired. */
- RETURN_INT(bytes_read);
+ break;
timersub(&end, &now, &delta);
}
result = select(port->fd + 1, &fds, NULL, NULL, timeout_ms ? &delta : NULL);
RETURN_FAIL("select() failed");
}
} else if (result == 0) {
- DEBUG("Read timed out");
- RETURN_INT(bytes_read);
+ /* Timeout has expired. */
+ break;
}
/* Do read. */
ptr += result;
}
+ if (bytes_read < count)
+ DEBUG("Read timed out");
+
RETURN_INT(bytes_read);
#endif
}