summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2016-05-05 08:42:17 +0000
committerPavel Labath <labath@google.com>2016-05-05 08:42:17 +0000
commitc14e8ced85ecaa4d6c65d91107d583c6b60fb25b (patch)
treedb389f48f1a8bc3c5450e4fbddc0fb10142301f2
parentc4f309a6bd20a64a97d42e26ee44f0b294f500d7 (diff)
downloadbcm5719-llvm-c14e8ced85ecaa4d6c65d91107d583c6b60fb25b.tar.gz
bcm5719-llvm-c14e8ced85ecaa4d6c65d91107d583c6b60fb25b.zip
Fix EOF handling in AdbClient (take 2)
Summary: AdbClient would spin in a loop in ReadAllBytes in case the remote end was closed before reading the requested number of bytes. Make sure we return an error in this case instead. Reviewers: ovyalov Subscribers: tberghammer, danalbert, lldb-commits Differential Revision: http://reviews.llvm.org/D19916 llvm-svn: 268617
-rw-r--r--lldb/source/Plugins/Platform/Android/AdbClient.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
index 736447fd22d..73eefebfdba 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
@@ -34,7 +34,7 @@ using namespace lldb_private::platform_android;
namespace {
-const uint32_t kReadTimeout = 1000000; // 1 second
+const std::chrono::seconds kReadTimeout(4);
const char * kOKAY = "OKAY";
const char * kFAIL = "FAIL";
const char * kDATA = "DATA";
@@ -490,18 +490,29 @@ AdbClient::ReadSyncHeader (std::string &response_id, uint32_t &data_len)
Error
AdbClient::ReadAllBytes (void *buffer, size_t size)
{
+ using namespace std::chrono;
+
Error error;
ConnectionStatus status;
char *read_buffer = static_cast<char*>(buffer);
- size_t tota_read_bytes = 0;
- while (tota_read_bytes < size)
+ auto now = steady_clock::now();
+ const auto deadline = now + kReadTimeout;
+ size_t total_read_bytes = 0;
+ while (total_read_bytes < size && now < deadline)
{
- auto read_bytes = m_conn.Read (read_buffer + tota_read_bytes, size - tota_read_bytes, kReadTimeout, status, &error);
+ uint32_t timeout_usec = duration_cast<microseconds>(deadline - now).count();
+ auto read_bytes =
+ m_conn.Read(read_buffer + total_read_bytes, size - total_read_bytes, timeout_usec, status, &error);
if (error.Fail ())
return error;
- tota_read_bytes += read_bytes;
+ total_read_bytes += read_bytes;
+ if (status != eConnectionStatusSuccess)
+ break;
+ now = steady_clock::now();
}
+ if (total_read_bytes < size)
+ error = Error("Unable to read requested number of bytes. Connection status: %d.", status);
return error;
}
OpenPOWER on IntegriCloud