From 2f159a5f93250706ad5bed6c2e8521ead4df749f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 25 Nov 2016 12:22:32 +0000 Subject: [PATCH] Introduce Chrono to the Connection class. NFCI. llvm-svn: 287922 --- lldb/include/lldb/Core/Connection.h | 13 ++++++++----- lldb/include/lldb/Core/ConnectionSharedMemory.h | 2 +- .../Host/posix/ConnectionFileDescriptorPosix.h | 4 ++-- lldb/source/Core/Communication.cpp | 7 ++----- lldb/source/Core/ConnectionSharedMemory.cpp | 2 +- lldb/source/Host/common/Editline.cpp | 4 ++-- .../posix/ConnectionFileDescriptorPosix.cpp | 17 +++++++++-------- .../Plugins/Platform/Android/AdbClient.cpp | 9 ++++----- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lldb/include/lldb/Core/Connection.h b/lldb/include/lldb/Core/Connection.h index 729d433b6085..6ff7b001a709 100644 --- a/lldb/include/lldb/Core/Connection.h +++ b/lldb/include/lldb/Core/Connection.h @@ -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 -// 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 &timeout, lldb::ConnectionStatus &status, Error *error_ptr) = 0; //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Core/ConnectionSharedMemory.h b/lldb/include/lldb/Core/ConnectionSharedMemory.h index 878d749bbc34..6062a16ea608 100644 --- a/lldb/include/lldb/Core/ConnectionSharedMemory.h +++ b/lldb/include/lldb/Core/ConnectionSharedMemory.h @@ -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 &timeout, lldb::ConnectionStatus &status, Error *error_ptr) override; size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, diff --git a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index ae33daaf497a..f002dd167ce2 100644 --- a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -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 &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 &timeout, Error *error_ptr); bool InterruptRead() override; diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index c82e2fe93681..113a847953d6 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -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."); diff --git a/lldb/source/Core/ConnectionSharedMemory.cpp b/lldb/source/Core/ConnectionSharedMemory.cpp index 05dec4856c2f..6cc2eb1b219b 100644 --- a/lldb/source/Core/ConnectionSharedMemory.cpp +++ b/lldb/source/Core/ConnectionSharedMemory.cpp @@ -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 &timeout, ConnectionStatus &status, Error *error_ptr) { status = eConnectionStatusSuccess; diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 6e12bfb89728..a600c61c8e6b 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -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; } diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index c1a6284ea62c..64101fdc4267 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -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 &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 &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(this), timeout_usec); + "%p ConnectionFileDescriptor::BytesAvailable (timeout_usec = %lu)", + static_cast(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) diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp index 05004406c04b..eb684ad0fbc0 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp +++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp @@ -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(deadline - now).count(); auto read_bytes = conn.Read(read_buffer + total_read_bytes, size - total_read_bytes, - timeout_usec, status, &error); + duration_cast(deadline - now), status, &error); if (error.Fail()) return error; total_read_bytes += read_bytes; @@ -276,9 +275,9 @@ Error AdbClient::ReadMessageStream(std::vector &message, if (elapsed >= timeout) return Error("Timed out"); - size_t n = m_conn->Read( - buffer, sizeof(buffer), - duration_cast(timeout - elapsed).count(), status, &error); + size_t n = m_conn->Read(buffer, sizeof(buffer), + duration_cast(timeout - elapsed), + status, &error); if (n > 0) message.insert(message.end(), &buffer[0], &buffer[n]); }