[Lldb-commits] [PATCH] D19916: Fix EOF handling in AdbClient (take 2)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu May 5 01:48:12 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL268617: Fix EOF handling in AdbClient (take 2) (authored by labath).

Changed prior to commit:
  http://reviews.llvm.org/D19916?vs=56134&id=56246#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19916

Files:
  lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp

Index: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
===================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
@@ -34,7 +34,7 @@
 
 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 @@
 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 read_bytes = m_conn.Read (read_buffer + tota_read_bytes, size - tota_read_bytes, kReadTimeout, status, &error);
+    auto now = steady_clock::now();
+    const auto deadline = now + kReadTimeout;
+    size_t total_read_bytes = 0;
+    while (total_read_bytes < size && now < deadline)
+    {
+        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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19916.56246.patch
Type: text/x-patch
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160505/27773c6c/attachment-0001.bin>


More information about the lldb-commits mailing list