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/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 SerialIoHandlerPosix::~SerialIoHandlerPosix() { | 167 SerialIoHandlerPosix::~SerialIoHandlerPosix() { |
168 } | 168 } |
169 | 169 |
170 void SerialIoHandlerPosix::OnFileCanReadWithoutBlocking(int fd) { | 170 void SerialIoHandlerPosix::OnFileCanReadWithoutBlocking(int fd) { |
171 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
172 DCHECK_EQ(fd, file().GetPlatformFile()); | 172 DCHECK_EQ(fd, file().GetPlatformFile()); |
173 | 173 |
174 if (pending_read_buffer()) { | 174 if (pending_read_buffer()) { |
175 int bytes_read = HANDLE_EINTR(read(file().GetPlatformFile(), | 175 int bytes_read = HANDLE_EINTR(read(file().GetPlatformFile(), |
176 pending_read_buffer()->data(), | 176 pending_read_buffer(), |
177 pending_read_buffer_len())); | 177 pending_read_buffer_len())); |
178 if (bytes_read < 0) { | 178 if (bytes_read < 0) { |
179 if (errno == ENXIO) { | 179 if (errno == ENXIO) { |
180 ReadCompleted(0, serial::RECEIVE_ERROR_DEVICE_LOST); | 180 ReadCompleted(0, serial::RECEIVE_ERROR_DEVICE_LOST); |
181 } else { | 181 } else { |
182 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); | 182 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); |
183 } | 183 } |
184 } else if (bytes_read == 0) { | 184 } else if (bytes_read == 0) { |
185 ReadCompleted(0, serial::RECEIVE_ERROR_DEVICE_LOST); | 185 ReadCompleted(0, serial::RECEIVE_ERROR_DEVICE_LOST); |
186 } else { | 186 } else { |
187 ReadCompleted(bytes_read, serial::RECEIVE_ERROR_NONE); | 187 ReadCompleted(bytes_read, serial::RECEIVE_ERROR_NONE); |
188 } | 188 } |
189 } else { | 189 } else { |
190 // Stop watching the fd if we get notifications with no pending | 190 // Stop watching the fd if we get notifications with no pending |
191 // reads or writes to avoid starving the message loop. | 191 // reads or writes to avoid starving the message loop. |
192 is_watching_reads_ = false; | 192 is_watching_reads_ = false; |
193 file_read_watcher_.StopWatchingFileDescriptor(); | 193 file_read_watcher_.StopWatchingFileDescriptor(); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) { | 197 void SerialIoHandlerPosix::OnFileCanWriteWithoutBlocking(int fd) { |
198 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
199 DCHECK_EQ(fd, file().GetPlatformFile()); | 199 DCHECK_EQ(fd, file().GetPlatformFile()); |
200 | 200 |
201 if (pending_write_buffer()) { | 201 if (pending_write_buffer()) { |
202 int bytes_written = HANDLE_EINTR(write(file().GetPlatformFile(), | 202 int bytes_written = HANDLE_EINTR(write(file().GetPlatformFile(), |
203 pending_write_buffer()->data(), | 203 pending_write_buffer(), |
204 pending_write_buffer_len())); | 204 pending_write_buffer_len())); |
205 if (bytes_written < 0) { | 205 if (bytes_written < 0) { |
206 WriteCompleted(0, serial::SEND_ERROR_SYSTEM_ERROR); | 206 WriteCompleted(0, serial::SEND_ERROR_SYSTEM_ERROR); |
207 } else { | 207 } else { |
208 WriteCompleted(bytes_written, serial::SEND_ERROR_NONE); | 208 WriteCompleted(bytes_written, serial::SEND_ERROR_NONE); |
209 } | 209 } |
210 } else { | 210 } else { |
211 // Stop watching the fd if we get notifications with no pending | 211 // Stop watching the fd if we get notifications with no pending |
212 // writes to avoid starving the message loop. | 212 // writes to avoid starving the message loop. |
213 is_watching_writes_ = false; | 213 is_watching_writes_ = false; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; | 403 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; |
404 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; | 404 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; |
405 return info.Pass(); | 405 return info.Pass(); |
406 } | 406 } |
407 | 407 |
408 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 408 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
409 return port_name; | 409 return port_name; |
410 } | 410 } |
411 | 411 |
412 } // namespace device | 412 } // namespace device |
OLD | NEW |