| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "tools/battor_agent/battor_connection_impl.h" | 5 #include "tools/battor_agent/battor_connection_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 void BattOrConnectionImpl::OnBytesRead(int bytes_read, | 215 void BattOrConnectionImpl::OnBytesRead(int bytes_read, |
| 216 device::serial::ReceiveError error) { | 216 device::serial::ReceiveError error) { |
| 217 if (error != device::serial::ReceiveError::NONE) { | 217 if (error != device::serial::ReceiveError::NONE) { |
| 218 LogSerial(StringPrintf( | 218 LogSerial(StringPrintf( |
| 219 "Read failed due to serial read failure with error code: %d.", | 219 "Read failed due to serial read failure with error code: %d.", |
| 220 static_cast<int>(error))); | 220 static_cast<int>(error))); |
| 221 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); | 221 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 if (bytes_read == 0) { | 225 // NOTE: Zero bytes may have been read. |
| 226 // If we didn't have a message before, and we weren't able to read any | |
| 227 // additional bytes, then there's no valid message available. | |
| 228 LogSerial("Read failed due to no bytes being read."); | |
| 229 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); | |
| 230 return; | |
| 231 } | |
| 232 | 226 |
| 233 if (pending_read_message_type_ == BATTOR_MESSAGE_TYPE_SAMPLES) { | 227 if (pending_read_message_type_ == BATTOR_MESSAGE_TYPE_SAMPLES) { |
| 234 // If we're reading samples, don't log every byte that we receive. This | 228 // If we're reading samples, don't log every byte that we receive. This |
| 235 // exacerbates a problem on Mac wherein we can't process sample frames | 229 // exacerbates a problem on Mac wherein we can't process sample frames |
| 236 // quickly enough to prevent the serial buffer from overflowing, causing us | 230 // quickly enough to prevent the serial buffer from overflowing, causing us |
| 237 // to drop frames. | 231 // to drop frames. |
| 238 LogSerial(StringPrintf("%d more bytes read.", bytes_read)); | 232 LogSerial(StringPrintf("%d more bytes read.", bytes_read)); |
| 239 } else { | 233 } else { |
| 240 LogSerial(StringPrintf( | 234 LogSerial(StringPrintf( |
| 241 "%d more bytes read: %s.", bytes_read, | 235 "%d more bytes read: %s.", bytes_read, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 base::ThreadTaskRunnerHandle::Get()->PostTask( | 348 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 355 FROM_HERE, | 349 FROM_HERE, |
| 356 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); | 350 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); |
| 357 } | 351 } |
| 358 | 352 |
| 359 void BattOrConnectionImpl::LogSerial(const std::string& str) { | 353 void BattOrConnectionImpl::LogSerial(const std::string& str) { |
| 360 serial_log_ << str << std::endl << std::endl; | 354 serial_log_ << str << std::endl << std::endl; |
| 361 } | 355 } |
| 362 | 356 |
| 363 } // namespace battor | 357 } // namespace battor |
| OLD | NEW |