mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Pre-fill buffer at start of read, to avoid the select if unnecessary.
This commit is contained in:
parent
c3855adbb0
commit
a9bf8d804d
@ -469,6 +469,14 @@ Serial::SerialImpl::read (uint8_t *buf, size_t size)
|
||||
total_timeout_ms += timeout_.read_timeout_multiplier * static_cast<long> (size);
|
||||
MillisecondTimer total_timeout(total_timeout_ms);
|
||||
|
||||
// Pre-fill buffer with available bytes
|
||||
{
|
||||
ssize_t bytes_read_now = ::read (fd_, buf, size);
|
||||
if (bytes_read_now > 0) {
|
||||
bytes_read = bytes_read_now;
|
||||
}
|
||||
}
|
||||
|
||||
while (bytes_read < size) {
|
||||
int64_t timeout_remaining_ms = total_timeout.remaining();
|
||||
if (timeout_remaining_ms <= 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user