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

Side by Side Diff: device/serial/serial_io_handler_posix.cc

Issue 2212273002: [serial] Cancel read watcher if immediate read succeeded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/serial/serial_io_handler_posix.h" 5 #include "device/serial/serial_io_handler_posix.h"
6 6
7 #include <sys/ioctl.h> 7 #include <sys/ioctl.h>
8 #include <termios.h> 8 #include <termios.h>
9 9
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 is_watching_reads_ = false; 341 is_watching_reads_ = false;
342 file_read_watcher_.StopWatchingFileDescriptor(); 342 file_read_watcher_.StopWatchingFileDescriptor();
343 } 343 }
344 344
345 return true; 345 return true;
346 } 346 }
347 347
348 void SerialIoHandlerPosix::RunReadCompleted(bool within_read, 348 void SerialIoHandlerPosix::RunReadCompleted(bool within_read,
349 int bytes_read, 349 int bytes_read,
350 serial::ReceiveError error) { 350 serial::ReceiveError error) {
351 if (within_read) 351 if (within_read) {
352 // Stop watching the fd to avoid more reads until the queued ReadCompleted()
353 // completes and releases the pending_read_buffer.
354 is_watching_reads_ = false;
355 file_read_watcher_.StopWatchingFileDescriptor();
356
352 QueueReadCompleted(bytes_read, error); 357 QueueReadCompleted(bytes_read, error);
353 else 358 } else {
354 ReadCompleted(bytes_read, error); 359 ReadCompleted(bytes_read, error);
360 }
355 } 361 }
356 362
357 void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) { 363 void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) {
358 DCHECK(CalledOnValidThread()); 364 DCHECK(CalledOnValidThread());
359 DCHECK_EQ(fd, file().GetPlatformFile()); 365 DCHECK_EQ(fd, file().GetPlatformFile());
360 366
361 if (pending_write_buffer()) { 367 if (pending_write_buffer()) {
362 int bytes_written = HANDLE_EINTR(write(file().GetPlatformFile(), 368 int bytes_written = HANDLE_EINTR(write(file().GetPlatformFile(),
363 pending_write_buffer(), 369 pending_write_buffer(),
364 pending_write_buffer_len())); 370 pending_write_buffer_len()));
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2)); 643 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2));
638 memcpy(chars_stashed_, tmp, num_chars_stashed_); 644 memcpy(chars_stashed_, tmp, num_chars_stashed_);
639 return new_bytes_read; 645 return new_bytes_read;
640 } 646 }
641 647
642 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { 648 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) {
643 return port_name; 649 return port_name;
644 } 650 }
645 651
646 } // namespace device 652 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698