Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1218)

Unified Diff: device/serial/serial_io_handler_posix.cc

Issue 2201893008: [serial] Only add a watcher if if the immeidate read attempt fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved to EAGAIN Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/serial/serial_io_handler_posix.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/serial/serial_io_handler_posix.cc
diff --git a/device/serial/serial_io_handler_posix.cc b/device/serial/serial_io_handler_posix.cc
index 3685ec8510d03c96ecde7239fa7c896cad675dd4..71b398c889b9eae7284bb699319f9114a50772a5 100644
--- a/device/serial/serial_io_handler_posix.cc
+++ b/device/serial/serial_io_handler_posix.cc
@@ -123,8 +123,6 @@ void SerialIoHandlerPosix::ReadImpl() {
DCHECK(pending_read_buffer());
DCHECK(file().IsValid());
- EnsureWatchingReads();
-
// Try to read immediately. This is needed because on some platforms
// (e.g., OSX) there may not be a notification from the message loop
// when the fd is ready to read immediately after it is opened. There
@@ -303,7 +301,7 @@ void SerialIoHandlerPosix::OnFileCanReadWithoutBlocking(int fd) {
AttemptRead(false);
}
-void SerialIoHandlerPosix::AttemptRead(bool within_read) {
+bool SerialIoHandlerPosix::AttemptRead(bool within_read) {
if (pending_read_buffer()) {
int bytes_read = HANDLE_EINTR(read(file().GetPlatformFile(),
pending_read_buffer(),
@@ -311,7 +309,7 @@ void SerialIoHandlerPosix::AttemptRead(bool within_read) {
if (bytes_read < 0) {
if (errno == EAGAIN) {
// The fd does not have data to read yet so continue waiting.
- return;
+ EnsureWatchingReads();
} else if (errno == ENXIO) {
RunReadCompleted(within_read, 0, serial::ReceiveError::DEVICE_LOST);
} else {
@@ -343,6 +341,8 @@ void SerialIoHandlerPosix::AttemptRead(bool within_read) {
is_watching_reads_ = false;
file_read_watcher_.StopWatchingFileDescriptor();
}
+
+ return true;
}
void SerialIoHandlerPosix::RunReadCompleted(bool within_read,
« no previous file with comments | « device/serial/serial_io_handler_posix.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698