Introduce Chrono to the Connection class. NFCI.

llvm-svn: 287922
This commit is contained in:
Pavel Labath 2016-11-25 12:22:32 +00:00
parent 3043fd8ff0
commit 2f159a5f93
8 changed files with 29 additions and 29 deletions

View File

@ -10,12 +10,14 @@
#ifndef liblldb_Connection_h_
#define liblldb_Connection_h_
// Other libraries and framework includes
// Project includes
#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-private.h"
// C Includes
// C++ Includes
#include <string>
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
namespace lldb_private {
@ -107,7 +109,7 @@ public:
/// The number of bytes to attempt to read, and also the max
/// number of bytes that can be placed into \a dst.
///
/// @param[in] timeout_usec
/// @param[in] timeout
/// The number of microseconds to wait for the data.
///
/// @param[out] status
@ -124,7 +126,8 @@ public:
///
/// @see size_t Communication::Read (void *, size_t, uint32_t);
//------------------------------------------------------------------
virtual size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec,
virtual size_t Read(void *dst, size_t dst_len,
const Timeout<std::micro> &timeout,
lldb::ConnectionStatus &status, Error *error_ptr) = 0;
//------------------------------------------------------------------

View File

@ -36,7 +36,7 @@ public:
lldb::ConnectionStatus Disconnect(Error *error_ptr) override;
size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec,
size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
lldb::ConnectionStatus &status, Error *error_ptr) override;
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,

View File

@ -57,7 +57,7 @@ public:
lldb::ConnectionStatus Disconnect(Error *error_ptr) override;
size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec,
size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
lldb::ConnectionStatus &status, Error *error_ptr) override;
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
@ -65,7 +65,7 @@ public:
std::string GetURI() override;
lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec,
lldb::ConnectionStatus BytesAvailable(const Timeout<std::micro> &timeout,
Error *error_ptr);
bool InterruptRead() override;

View File

@ -278,11 +278,8 @@ size_t Communication::ReadFromConnection(void *dst, size_t dst_len,
ConnectionStatus &status,
Error *error_ptr) {
lldb::ConnectionSP connection_sp(m_connection_sp);
if (connection_sp) {
return connection_sp->Read(dst, dst_len,
timeout ? timeout->count() : UINT32_MAX, status,
error_ptr);
}
if (connection_sp)
return connection_sp->Read(dst, dst_len, timeout, status, error_ptr);
if (error_ptr)
error_ptr->SetErrorString("Invalid connection.");

View File

@ -79,7 +79,7 @@ ConnectionStatus ConnectionSharedMemory::Disconnect(Error *error_ptr) {
}
size_t ConnectionSharedMemory::Read(void *dst, size_t dst_len,
uint32_t timeout_usec,
const Timeout<std::micro> &timeout,
ConnectionStatus &status,
Error *error_ptr) {
status = eConnectionStatusSuccess;

View File

@ -516,11 +516,11 @@ int Editline::GetCharacter(EditLineCharType *c) {
// mutex again and
// check if we were interrupted.
m_output_mutex.unlock();
int read_count = m_input_connection.Read(&ch, 1, UINT32_MAX, status, NULL);
int read_count = m_input_connection.Read(&ch, 1, llvm::None, status, NULL);
m_output_mutex.lock();
if (m_editor_status == EditorStatus::Interrupted) {
while (read_count > 0 && status == lldb::eConnectionStatusSuccess)
read_count = m_input_connection.Read(&ch, 1, UINT32_MAX, status, NULL);
read_count = m_input_connection.Read(&ch, 1, llvm::None, status, NULL);
lldbassert(status == lldb::eConnectionStatusInterrupted);
return 0;
}

View File

@ -369,7 +369,7 @@ ConnectionStatus ConnectionFileDescriptor::Disconnect(Error *error_ptr) {
}
size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
uint32_t timeout_usec,
const Timeout<std::micro> &timeout,
ConnectionStatus &status,
Error *error_ptr) {
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
@ -392,7 +392,7 @@ size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
return 0;
}
status = BytesAvailable(timeout_usec, error_ptr);
status = BytesAvailable(timeout, error_ptr);
if (status != eConnectionStatusSuccess)
return 0;
@ -553,8 +553,9 @@ std::string ConnectionFileDescriptor::GetURI() { return m_uri; }
// be used or a new version of ConnectionFileDescriptor::BytesAvailable()
// should be written for the system that is running into the limitations.
ConnectionStatus ConnectionFileDescriptor::BytesAvailable(uint32_t timeout_usec,
Error *error_ptr) {
ConnectionStatus
ConnectionFileDescriptor::BytesAvailable(const Timeout<std::micro> &timeout,
Error *error_ptr) {
// Don't need to take the mutex here separately since we are only called from
// Read. If we
// ever get used more generally we will need to lock here as well.
@ -562,8 +563,8 @@ ConnectionStatus ConnectionFileDescriptor::BytesAvailable(uint32_t timeout_usec,
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_CONNECTION));
if (log)
log->Printf(
"%p ConnectionFileDescriptor::BytesAvailable (timeout_usec = %u)",
static_cast<void *>(this), timeout_usec);
"%p ConnectionFileDescriptor::BytesAvailable (timeout_usec = %lu)",
static_cast<void *>(this), long(timeout ? timeout->count() : -1));
// Make a copy of the file descriptors to make sure we don't
// have another thread change these values out from under us
@ -573,8 +574,8 @@ ConnectionStatus ConnectionFileDescriptor::BytesAvailable(uint32_t timeout_usec,
if (handle != IOObject::kInvalidHandleValue) {
SelectHelper select_helper;
if (timeout_usec != UINT32_MAX)
select_helper.SetTimeout(std::chrono::microseconds(timeout_usec));
if (timeout)
select_helper.SetTimeout(*timeout);
select_helper.FDSetRead(handle);
#if defined(_MSC_VER)

View File

@ -74,10 +74,9 @@ Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
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 =
conn.Read(read_buffer + total_read_bytes, size - total_read_bytes,
timeout_usec, status, &error);
duration_cast<microseconds>(deadline - now), status, &error);
if (error.Fail())
return error;
total_read_bytes += read_bytes;
@ -276,9 +275,9 @@ Error AdbClient::ReadMessageStream(std::vector<char> &message,
if (elapsed >= timeout)
return Error("Timed out");
size_t n = m_conn->Read(
buffer, sizeof(buffer),
duration_cast<microseconds>(timeout - elapsed).count(), status, &error);
size_t n = m_conn->Read(buffer, sizeof(buffer),
duration_cast<microseconds>(timeout - elapsed),
status, &error);
if (n > 0)
message.insert(message.end(), &buffer[0], &buffer[n]);
}