2010-06-09 00:52:24 +08:00
|
|
|
//===-- Communication.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/lldb-private-log.h"
|
|
|
|
#include "lldb/Core/Communication.h"
|
|
|
|
#include "lldb/Core/Connection.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/Timer.h"
|
|
|
|
#include "lldb/Core/Event.h"
|
2011-02-01 09:31:41 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/HostThread.h"
|
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
2010-06-09 16:50:27 +08:00
|
|
|
#include <string.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-02-16 14:50:00 +08:00
|
|
|
ConstString &
|
|
|
|
Communication::GetStaticBroadcasterClass ()
|
|
|
|
{
|
|
|
|
static ConstString class_name ("lldb.communication");
|
|
|
|
return class_name;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-12-04 10:39:47 +08:00
|
|
|
Communication::Communication(const char *name) :
|
2012-02-16 14:50:00 +08:00
|
|
|
Broadcaster (NULL, name),
|
2010-12-14 10:59:59 +08:00
|
|
|
m_connection_sp (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_read_thread_enabled (false),
|
|
|
|
m_bytes(),
|
|
|
|
m_bytes_mutex (Mutex::eMutexTypeRecursive),
|
2011-01-27 17:02:32 +08:00
|
|
|
m_write_mutex (Mutex::eMutexTypeNormal),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_callback (NULL),
|
2010-12-03 02:31:56 +08:00
|
|
|
m_callback_baton (NULL),
|
2010-12-04 10:39:47 +08:00
|
|
|
m_close_on_eof (true)
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
|
|
|
|
"%p Communication::Communication (name = %s)",
|
|
|
|
this, name);
|
2011-04-01 08:29:43 +08:00
|
|
|
|
|
|
|
SetEventName (eBroadcastBitDisconnected, "disconnected");
|
|
|
|
SetEventName (eBroadcastBitReadThreadGotBytes, "got bytes");
|
|
|
|
SetEventName (eBroadcastBitReadThreadDidExit, "read thread did exit");
|
|
|
|
SetEventName (eBroadcastBitReadThreadShouldExit, "read thread should exit");
|
|
|
|
SetEventName (eBroadcastBitPacketAvailable, "packet available");
|
2012-02-16 14:50:00 +08:00
|
|
|
|
|
|
|
CheckInWithManager();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Communication::~Communication()
|
|
|
|
{
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
|
|
|
|
"%p Communication::~Communication (name = %s)",
|
|
|
|
this, m_broadcaster_name.AsCString(""));
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Communication::Clear()
|
|
|
|
{
|
2011-08-20 07:28:37 +08:00
|
|
|
SetReadThreadBytesReceivedCallback (NULL, NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
Disconnect (NULL);
|
2012-01-31 12:56:17 +08:00
|
|
|
StopReadThread (NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionStatus
|
|
|
|
Communication::Connect (const char *url, Error *error_ptr)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::Connect (url = %s)", this, url);
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
if (connection_sp.get())
|
|
|
|
return connection_sp->Connect (url, error_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
return eConnectionStatusNoConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionStatus
|
|
|
|
Communication::Disconnect (Error *error_ptr)
|
|
|
|
{
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::Disconnect ()", this);
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
if (connection_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
ConnectionStatus status = connection_sp->Disconnect (error_ptr);
|
|
|
|
// We currently don't protect connection_sp with any mutex for
|
2010-12-13 05:50:57 +08:00
|
|
|
// multi-threaded environments. So lets not nuke our connection class
|
|
|
|
// without putting some multi-threaded protections in. We also probably
|
|
|
|
// don't want to pay for the overhead it might cause if every time we
|
|
|
|
// access the connection we have to take a lock.
|
|
|
|
//
|
2013-04-19 02:10:51 +08:00
|
|
|
// This unique pointer will cleanup after itself when this object goes away,
|
2010-12-13 05:50:57 +08:00
|
|
|
// so there is no need to currently have it destroy itself immediately
|
|
|
|
// upon disconnnect.
|
2010-12-14 10:59:59 +08:00
|
|
|
//connection_sp.reset();
|
2010-06-09 00:52:24 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return eConnectionStatusNoConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Communication::IsConnected () const
|
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
if (connection_sp.get())
|
|
|
|
return connection_sp->IsConnected ();
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Communication::HasConnection () const
|
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
return m_connection_sp.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, ConnectionStatus &status, Error *error_ptr)
|
|
|
|
{
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
|
2012-11-30 05:49:15 +08:00
|
|
|
"%p Communication::Read (dst = %p, dst_len = %" PRIu64 ", timeout = %u usec) connection = %p",
|
2010-12-14 10:59:59 +08:00
|
|
|
this,
|
|
|
|
dst,
|
2012-09-19 02:04:04 +08:00
|
|
|
(uint64_t)dst_len,
|
2010-12-14 10:59:59 +08:00
|
|
|
timeout_usec,
|
|
|
|
m_connection_sp.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-01-12 12:22:54 +08:00
|
|
|
if (m_read_thread_enabled)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// We have a dedicated read thread that is getting data for us
|
|
|
|
size_t cached_bytes = GetCachedBytes (dst, dst_len);
|
|
|
|
if (cached_bytes > 0 || timeout_usec == 0)
|
|
|
|
{
|
|
|
|
status = eConnectionStatusSuccess;
|
|
|
|
return cached_bytes;
|
|
|
|
}
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
if (m_connection_sp.get() == NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Set the timeout appropriately
|
|
|
|
TimeValue timeout_time;
|
|
|
|
if (timeout_usec != UINT32_MAX)
|
|
|
|
{
|
|
|
|
timeout_time = TimeValue::Now();
|
|
|
|
timeout_time.OffsetWithMicroSeconds (timeout_usec);
|
|
|
|
}
|
|
|
|
|
|
|
|
Listener listener ("Communication::Read");
|
|
|
|
listener.StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
|
|
|
|
EventSP event_sp;
|
|
|
|
while (listener.WaitForEvent (timeout_time.IsValid() ? &timeout_time : NULL, event_sp))
|
|
|
|
{
|
|
|
|
const uint32_t event_type = event_sp->GetType();
|
|
|
|
if (event_type & eBroadcastBitReadThreadGotBytes)
|
|
|
|
{
|
|
|
|
return GetCachedBytes (dst, dst_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_type & eBroadcastBitReadThreadDidExit)
|
|
|
|
{
|
|
|
|
Disconnect (NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We aren't using a read thread, just read the data synchronously in this
|
|
|
|
// thread.
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
if (connection_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-06-17 09:22:15 +08:00
|
|
|
return connection_sp->Read (dst, dst_len, timeout_usec, status, error_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Communication::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
|
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
|
2012-10-05 06:47:07 +08:00
|
|
|
Mutex::Locker locker(m_write_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
|
2012-11-30 05:49:15 +08:00
|
|
|
"%p Communication::Write (src = %p, src_len = %" PRIu64 ") connection = %p",
|
2010-12-14 10:59:59 +08:00
|
|
|
this,
|
|
|
|
src,
|
2012-09-19 02:04:04 +08:00
|
|
|
(uint64_t)src_len,
|
2010-12-14 10:59:59 +08:00
|
|
|
connection_sp.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
if (connection_sp.get())
|
|
|
|
return connection_sp->Write (src, src_len, status, error_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
Communication::StartReadThread (Error *error_ptr)
|
|
|
|
{
|
2011-03-24 12:28:38 +08:00
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->Clear();
|
|
|
|
|
2014-09-24 02:32:09 +08:00
|
|
|
if (m_read_thread.IsJoinable())
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
|
|
|
|
"%p Communication::StartReadThread ()", this);
|
|
|
|
|
|
|
|
|
|
|
|
char thread_name[1024];
|
|
|
|
snprintf(thread_name, sizeof(thread_name), "<lldb.comm.%s>", m_broadcaster_name.AsCString());
|
|
|
|
|
2010-09-15 13:19:45 +08:00
|
|
|
m_read_thread_enabled = true;
|
2014-09-10 04:54:56 +08:00
|
|
|
m_read_thread = ThreadLauncher::LaunchThread(thread_name, Communication::ReadThread, this, error_ptr);
|
2014-09-24 02:32:09 +08:00
|
|
|
if (!m_read_thread.IsJoinable())
|
2010-09-15 13:19:45 +08:00
|
|
|
m_read_thread_enabled = false;
|
2010-07-23 23:43:25 +08:00
|
|
|
return m_read_thread_enabled;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Communication::StopReadThread (Error *error_ptr)
|
|
|
|
{
|
2014-09-24 02:32:09 +08:00
|
|
|
if (!m_read_thread.IsJoinable())
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
|
|
|
|
"%p Communication::StopReadThread ()", this);
|
|
|
|
|
|
|
|
m_read_thread_enabled = false;
|
|
|
|
|
|
|
|
BroadcastEvent (eBroadcastBitReadThreadShouldExit, NULL);
|
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
// error = m_read_thread.Cancel();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
Error error = m_read_thread.Join(nullptr);
|
|
|
|
return error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2014-01-31 02:52:57 +08:00
|
|
|
bool
|
|
|
|
Communication::JoinReadThread (Error *error_ptr)
|
|
|
|
{
|
2014-09-24 02:32:09 +08:00
|
|
|
if (!m_read_thread.IsJoinable())
|
2014-01-31 02:52:57 +08:00
|
|
|
return true;
|
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
Error error = m_read_thread.Join(nullptr);
|
|
|
|
return error.Success();
|
2014-01-31 02:52:57 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
Communication::GetCachedBytes (void *dst, size_t dst_len)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker(m_bytes_mutex);
|
|
|
|
if (m_bytes.size() > 0)
|
|
|
|
{
|
|
|
|
// If DST is NULL and we have a thread, then return the number
|
|
|
|
// of bytes that are available so the caller can call again
|
|
|
|
if (dst == NULL)
|
|
|
|
return m_bytes.size();
|
|
|
|
|
|
|
|
const size_t len = std::min<size_t>(dst_len, m_bytes.size());
|
|
|
|
|
2010-07-21 06:52:08 +08:00
|
|
|
::memcpy (dst, m_bytes.c_str(), len);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_bytes.erase(m_bytes.begin(), m_bytes.begin() + len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-20 04:47:54 +08:00
|
|
|
Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast, ConnectionStatus status)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
|
2012-11-30 05:49:15 +08:00
|
|
|
"%p Communication::AppendBytesToCache (src = %p, src_len = %" PRIu64 ", broadcast = %i)",
|
2012-09-19 02:04:04 +08:00
|
|
|
this, bytes, (uint64_t)len, broadcast);
|
2011-02-04 04:02:43 +08:00
|
|
|
if ((bytes == NULL || len == 0)
|
|
|
|
&& (status != lldb::eConnectionStatusEndOfFile))
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
// If the user registered a callback, then call it and do not broadcast
|
|
|
|
m_callback (m_callback_baton, bytes, len);
|
|
|
|
}
|
2011-08-20 07:28:37 +08:00
|
|
|
else if (bytes != NULL && len > 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker(m_bytes_mutex);
|
|
|
|
m_bytes.append ((const char *)bytes, len);
|
|
|
|
if (broadcast)
|
|
|
|
BroadcastEventIfUnique (eBroadcastBitReadThreadGotBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2011-06-17 09:22:15 +08:00
|
|
|
Communication::ReadFromConnection (void *dst,
|
|
|
|
size_t dst_len,
|
|
|
|
uint32_t timeout_usec,
|
|
|
|
ConnectionStatus &status,
|
|
|
|
Error *error_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::ConnectionSP connection_sp (m_connection_sp);
|
|
|
|
if (connection_sp.get())
|
2011-06-17 09:22:15 +08:00
|
|
|
return connection_sp->Read (dst, dst_len, timeout_usec, status, error_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Communication::ReadThreadIsRunning ()
|
|
|
|
{
|
2011-01-12 12:22:54 +08:00
|
|
|
return m_read_thread_enabled;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:05 +08:00
|
|
|
lldb::thread_result_t
|
|
|
|
Communication::ReadThread (lldb::thread_arg_t p)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Communication *comm = (Communication *)p;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_COMMUNICATION));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf ("%p Communication::ReadThread () thread starting...", p);
|
|
|
|
|
|
|
|
uint8_t buf[1024];
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
ConnectionStatus status = eConnectionStatusSuccess;
|
|
|
|
bool done = false;
|
|
|
|
while (!done && comm->m_read_thread_enabled)
|
|
|
|
{
|
2011-06-19 07:52:14 +08:00
|
|
|
size_t bytes_read = comm->ReadFromConnection (buf, sizeof(buf), 5 * TimeValue::MicroSecPerSec, status, &error);
|
2011-06-17 09:22:15 +08:00
|
|
|
if (bytes_read > 0)
|
|
|
|
comm->AppendBytesToCache (buf, bytes_read, true, status);
|
|
|
|
else if ((bytes_read == 0)
|
|
|
|
&& status == eConnectionStatusEndOfFile)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-06-17 09:22:15 +08:00
|
|
|
if (comm->GetCloseOnEOF ())
|
|
|
|
comm->Disconnect ();
|
|
|
|
comm->AppendBytesToCache (buf, bytes_read, true, status);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case eConnectionStatusSuccess:
|
|
|
|
break;
|
|
|
|
|
2010-12-04 10:22:36 +08:00
|
|
|
case eConnectionStatusEndOfFile:
|
2011-02-04 04:02:43 +08:00
|
|
|
if (comm->GetCloseOnEOF())
|
|
|
|
done = true;
|
|
|
|
break;
|
2014-08-22 01:16:26 +08:00
|
|
|
case eConnectionStatusError: // Check GetError() for details
|
|
|
|
if (error.GetType() == eErrorTypePOSIX && error.GetError() == EIO)
|
|
|
|
{
|
|
|
|
// EIO on a pipe is usually caused by remote shutdown
|
|
|
|
comm->Disconnect ();
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (log)
|
|
|
|
error.LogIfError (log,
|
|
|
|
"%p Communication::ReadFromConnection () => status = %s",
|
|
|
|
p,
|
|
|
|
Communication::ConnectionStatusAsCString (status));
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case eConnectionStatusNoConnection: // No connection
|
|
|
|
case eConnectionStatusLostConnection: // Lost connection while connected to a valid connection
|
2014-05-02 08:45:31 +08:00
|
|
|
case eConnectionStatusInterrupted: // Interrupted
|
2010-06-09 00:52:24 +08:00
|
|
|
done = true;
|
|
|
|
// Fall through...
|
|
|
|
case eConnectionStatusTimedOut: // Request timed out
|
2010-11-06 09:53:30 +08:00
|
|
|
if (log)
|
2013-03-28 07:08:40 +08:00
|
|
|
error.LogIfError (log,
|
|
|
|
"%p Communication::ReadFromConnection () => status = %s",
|
|
|
|
p,
|
|
|
|
Communication::ConnectionStatusAsCString (status));
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-10-30 05:48:37 +08:00
|
|
|
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_COMMUNICATION);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%p Communication::ReadThread () thread exiting...", p);
|
|
|
|
|
|
|
|
// Let clients know that this thread is exiting
|
|
|
|
comm->BroadcastEvent (eBroadcastBitReadThreadDidExit);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Communication::SetReadThreadBytesReceivedCallback
|
|
|
|
(
|
|
|
|
ReadThreadBytesReceived callback,
|
|
|
|
void *callback_baton
|
|
|
|
)
|
|
|
|
{
|
|
|
|
m_callback = callback;
|
|
|
|
m_callback_baton = callback_baton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Communication::SetConnection (Connection *connection)
|
|
|
|
{
|
|
|
|
Disconnect (NULL);
|
2012-01-31 12:56:17 +08:00
|
|
|
StopReadThread(NULL);
|
2010-12-14 10:59:59 +08:00
|
|
|
m_connection_sp.reset(connection);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
const char *
|
|
|
|
Communication::ConnectionStatusAsCString (lldb::ConnectionStatus status)
|
|
|
|
{
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case eConnectionStatusSuccess: return "success";
|
|
|
|
case eConnectionStatusError: return "error";
|
|
|
|
case eConnectionStatusTimedOut: return "timed out";
|
|
|
|
case eConnectionStatusNoConnection: return "no connection";
|
|
|
|
case eConnectionStatusLostConnection: return "lost connection";
|
2011-03-20 12:57:14 +08:00
|
|
|
case eConnectionStatusEndOfFile: return "end of file";
|
2014-05-02 08:45:31 +08:00
|
|
|
case eConnectionStatusInterrupted: return "interrupted";
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char unknown_state_string[64];
|
|
|
|
snprintf(unknown_state_string, sizeof (unknown_state_string), "ConnectionStatus = %i", status);
|
|
|
|
return unknown_state_string;
|
|
|
|
}
|