OLD | NEW |
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/files/file_util.h" |
10 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
13 #if defined(OS_LINUX) | 14 #if defined(OS_LINUX) |
14 #include <linux/serial.h> | 15 #include <linux/serial.h> |
15 | 16 |
16 // The definition of struct termios2 is copied from asm-generic/termbits.h | 17 // The definition of struct termios2 is copied from asm-generic/termbits.h |
17 // because including that header directly conflicts with termios.h. | 18 // because including that header directly conflicts with termios.h. |
18 extern "C" { | 19 extern "C" { |
19 struct termios2 { | 20 struct termios2 { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 if (ioctl(file().GetPlatformFile(), IOSSIOSPEED, &bitrate) == -1) { | 275 if (ioctl(file().GetPlatformFile(), IOSSIOSPEED, &bitrate) == -1) { |
275 VPLOG(1) << "Failed to set custom baud rate"; | 276 VPLOG(1) << "Failed to set custom baud rate"; |
276 return false; | 277 return false; |
277 } | 278 } |
278 } | 279 } |
279 #endif | 280 #endif |
280 | 281 |
281 return true; | 282 return true; |
282 } | 283 } |
283 | 284 |
| 285 bool SerialIoHandlerPosix::PostOpen() { |
| 286 #if defined(OS_CHROMEOS) |
| 287 // The Chrome OS permission broker does not open devices in async mode. |
| 288 return base::SetNonBlocking(file().GetPlatformFile()); |
| 289 #else |
| 290 return true; |
| 291 #endif |
| 292 } |
| 293 |
284 SerialIoHandlerPosix::SerialIoHandlerPosix( | 294 SerialIoHandlerPosix::SerialIoHandlerPosix( |
285 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 295 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
286 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) | 296 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_task_runner) |
287 : SerialIoHandler(file_thread_task_runner, ui_thread_task_runner) {} | 297 : SerialIoHandler(file_thread_task_runner, ui_thread_task_runner) {} |
288 | 298 |
289 SerialIoHandlerPosix::~SerialIoHandlerPosix() { | 299 SerialIoHandlerPosix::~SerialIoHandlerPosix() { |
290 } | 300 } |
291 | 301 |
292 void SerialIoHandlerPosix::AttemptRead(bool within_read) { | 302 void SerialIoHandlerPosix::AttemptRead(bool within_read) { |
293 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2)); | 631 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2)); |
622 memcpy(chars_stashed_, tmp, num_chars_stashed_); | 632 memcpy(chars_stashed_, tmp, num_chars_stashed_); |
623 return new_bytes_read; | 633 return new_bytes_read; |
624 } | 634 } |
625 | 635 |
626 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 636 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
627 return port_name; | 637 return port_name; |
628 } | 638 } |
629 | 639 |
630 } // namespace device | 640 } // namespace device |
OLD | NEW |