| 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "device/serial/serial_io_handler_win.h" | 7 #include "device/serial/serial_io_handler_win.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 is_comm_pending_ = true; | 211 is_comm_pending_ = true; |
| 212 } | 212 } |
| 213 | 213 |
| 214 void SerialIoHandlerWin::WriteImpl() { | 214 void SerialIoHandlerWin::WriteImpl() { |
| 215 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 216 DCHECK(pending_write_buffer()); | 216 DCHECK(pending_write_buffer()); |
| 217 DCHECK(file().IsValid()); | 217 DCHECK(file().IsValid()); |
| 218 | 218 |
| 219 BOOL ok = ::WriteFile(file().GetPlatformFile(), | 219 BOOL ok = ::WriteFile(file().GetPlatformFile(), |
| 220 pending_write_buffer()->data(), | 220 pending_write_buffer(), |
| 221 pending_write_buffer_len(), | 221 pending_write_buffer_len(), |
| 222 NULL, | 222 NULL, |
| 223 &write_context_->overlapped); | 223 &write_context_->overlapped); |
| 224 if (!ok && GetLastError() != ERROR_IO_PENDING) { | 224 if (!ok && GetLastError() != ERROR_IO_PENDING) { |
| 225 QueueWriteCompleted(0, serial::SEND_ERROR_SYSTEM_ERROR); | 225 QueueWriteCompleted(0, serial::SEND_ERROR_SYSTEM_ERROR); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void SerialIoHandlerWin::CancelReadImpl() { | 229 void SerialIoHandlerWin::CancelReadImpl() { |
| 230 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 253 DWORD bytes_transferred, | 253 DWORD bytes_transferred, |
| 254 DWORD error) { | 254 DWORD error) { |
| 255 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
| 256 if (context == comm_context_) { | 256 if (context == comm_context_) { |
| 257 if (read_canceled()) { | 257 if (read_canceled()) { |
| 258 ReadCompleted(bytes_transferred, read_cancel_reason()); | 258 ReadCompleted(bytes_transferred, read_cancel_reason()); |
| 259 } else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) { | 259 } else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) { |
| 260 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); | 260 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); |
| 261 } else if (pending_read_buffer()) { | 261 } else if (pending_read_buffer()) { |
| 262 BOOL ok = ::ReadFile(file().GetPlatformFile(), | 262 BOOL ok = ::ReadFile(file().GetPlatformFile(), |
| 263 pending_read_buffer()->data(), | 263 pending_read_buffer(), |
| 264 pending_read_buffer_len(), | 264 pending_read_buffer_len(), |
| 265 NULL, | 265 NULL, |
| 266 &read_context_->overlapped); | 266 &read_context_->overlapped); |
| 267 if (!ok && GetLastError() != ERROR_IO_PENDING) { | 267 if (!ok && GetLastError() != ERROR_IO_PENDING) { |
| 268 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); | 268 ReadCompleted(0, serial::RECEIVE_ERROR_SYSTEM_ERROR); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 } else if (context == read_context_) { | 271 } else if (context == read_context_) { |
| 272 if (read_canceled()) { | 272 if (read_canceled()) { |
| 273 ReadCompleted(bytes_transferred, read_cancel_reason()); | 273 ReadCompleted(bytes_transferred, read_cancel_reason()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 376 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
| 377 // For COM numbers less than 9, CreateFile is called with a string such as | 377 // For COM numbers less than 9, CreateFile is called with a string such as |
| 378 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. | 378 // "COM1". For numbers greater than 9, a prefix of "\\\\.\\" must be added. |
| 379 if (port_name.length() > std::string("COM9").length()) | 379 if (port_name.length() > std::string("COM9").length()) |
| 380 return std::string("\\\\.\\").append(port_name); | 380 return std::string("\\\\.\\").append(port_name); |
| 381 | 381 |
| 382 return port_name; | 382 return port_name; |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace device | 385 } // namespace device |
| OLD | NEW |