[Lldb-commits] [lldb] r287879 - Use chrono in AdbClient
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 24 06:03:57 PST 2016
Author: labath
Date: Thu Nov 24 08:03:57 2016
New Revision: 287879
URL: http://llvm.org/viewvc/llvm-project?rev=287879&view=rev
Log:
Use chrono in AdbClient
This refactors the class implementations to use chrono. I'll follow this up with
a refactor of the class interface.
Modified:
lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=287879&r1=287878&r2=287879&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Thu Nov 24 08:03:57 2016
@@ -41,10 +41,11 @@
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::platform_android;
+using namespace std::chrono;
namespace {
-const std::chrono::seconds kReadTimeout(8);
+const seconds kReadTimeout(8);
const char *kOKAY = "OKAY";
const char *kFAIL = "FAIL";
const char *kDATA = "DATA";
@@ -64,7 +65,6 @@ const char *kSocketNamespaceAbstract = "
const char *kSocketNamespaceFileSystem = "localfilesystem";
Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
- using namespace std::chrono;
Error error;
ConnectionStatus status;
@@ -263,23 +263,22 @@ Error AdbClient::ReadMessage(std::vector
}
Error AdbClient::ReadMessageStream(std::vector<char> &message,
- uint32_t timeout_ms) {
- auto start = std::chrono::steady_clock::now();
+ milliseconds timeout) {
+ auto start = steady_clock::now();
message.clear();
Error error;
lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
char buffer[1024];
while (error.Success() && status == lldb::eConnectionStatusSuccess) {
- auto end = std::chrono::steady_clock::now();
- uint32_t elapsed_time =
- std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
- .count();
- if (elapsed_time >= timeout_ms)
+ auto end = steady_clock::now();
+ auto elapsed = end - start;
+ if (elapsed >= timeout)
return Error("Timed out");
- size_t n = m_conn->Read(buffer, sizeof(buffer),
- 1000 * (timeout_ms - elapsed_time), status, &error);
+ size_t n = m_conn->Read(
+ buffer, sizeof(buffer),
+ duration_cast<microseconds>(timeout - elapsed).count(), status, &error);
if (n > 0)
message.insert(message.end(), &buffer[0], &buffer[n]);
}
@@ -350,7 +349,7 @@ Error AdbClient::ReadAllBytes(void *buff
return ::ReadAllBytes(*m_conn, buffer, size);
}
-Error AdbClient::internalShell(const char *command, uint32_t timeout_ms,
+Error AdbClient::internalShell(const char *command, milliseconds timeout,
std::vector<char> &output_buf) {
output_buf.clear();
@@ -368,7 +367,7 @@ Error AdbClient::internalShell(const cha
if (error.Fail())
return error;
- error = ReadMessageStream(output_buf, timeout_ms);
+ error = ReadMessageStream(output_buf, timeout);
if (error.Fail())
return error;
@@ -387,7 +386,7 @@ Error AdbClient::internalShell(const cha
Error AdbClient::Shell(const char *command, uint32_t timeout_ms,
std::string *output) {
std::vector<char> output_buffer;
- auto error = internalShell(command, timeout_ms, output_buffer);
+ auto error = internalShell(command, milliseconds(timeout_ms), output_buffer);
if (error.Fail())
return error;
@@ -399,7 +398,7 @@ Error AdbClient::Shell(const char *comma
Error AdbClient::ShellToFile(const char *command, uint32_t timeout_ms,
const FileSpec &output_file_spec) {
std::vector<char> output_buffer;
- auto error = internalShell(command, timeout_ms, output_buffer);
+ auto error = internalShell(command, milliseconds(timeout_ms), output_buffer);
if (error.Fail())
return error;
@@ -477,9 +476,7 @@ Error AdbClient::SyncService::internalPu
return Error("Failed to send file chunk: %s", error.AsCString());
}
error = SendSyncRequest(
- kDONE, std::chrono::duration_cast<std::chrono::seconds>(
- FileSystem::GetModificationTime(local_file).time_since_epoch())
- .count(),
+ kDONE, llvm::sys::toTimeT(FileSystem::GetModificationTime(local_file)),
nullptr);
if (error.Fail())
return error;
Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.h?rev=287879&r1=287878&r2=287879&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.h Thu Nov 24 08:03:57 2016
@@ -10,21 +10,14 @@
#ifndef liblldb_AdbClient_h_
#define liblldb_AdbClient_h_
-// C Includes
-
-// C++ Includes
-
+#include "lldb/Core/Error.h"
+#include <chrono>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <vector>
-// Other libraries and framework includes
-// Project includes
-
-#include "lldb/Core/Error.h"
-
namespace lldb_private {
class FileSpec;
@@ -121,7 +114,7 @@ private:
Error ReadMessage(std::vector<char> &message);
- Error ReadMessageStream(std::vector<char> &message, uint32_t timeout_ms);
+ Error ReadMessageStream(std::vector<char> &message, std::chrono::milliseconds timeout);
Error GetResponseError(const char *response_id);
@@ -131,7 +124,7 @@ private:
Error StartSync();
- Error internalShell(const char *command, uint32_t timeout_ms,
+ Error internalShell(const char *command, std::chrono::milliseconds timeout,
std::vector<char> &output_buf);
Error ReadAllBytes(void *buffer, size_t size);
More information about the lldb-commits
mailing list