Skip to content

Commit

Permalink
Pre-fill buffer at start of read, to avoid the select if unnecessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Nov 18, 2013
1 parent c3855ad commit a9bf8d8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/impl/unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a9bf8d8

Please sign in to comment.