summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorCaroline Tice <ctice@apple.com>2010-12-02 18:31:56 +0000
committerCaroline Tice <ctice@apple.com>2010-12-02 18:31:56 +0000
commit82305fc59a70f3b10b07235daa2601d08aebf0d3 (patch)
tree74952ab66af36d82fb8ee84274984fc97d055520 /lldb/source/Core
parentc5cc2fb980f8ccd0c16b30148a6a7e8776136c23 (diff)
downloadbcm5719-llvm-82305fc59a70f3b10b07235daa2601d08aebf0d3.tar.gz
bcm5719-llvm-82305fc59a70f3b10b07235daa2601d08aebf0d3.zip
Add proper EOF handling to Communication & Connection classes:
Add bool member to Communication class indicating whether the Connection should be closed on receiving an EOF or not. Update the Connection read to return an EOF status when appropriate. Modify the Communication class to pass the EOF along or not, and to close the Connection or not, as appropriate. llvm-svn: 120723
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/Communication.cpp22
-rw-r--r--lldb/source/Core/ConnectionFileDescriptor.cpp4
-rw-r--r--lldb/source/Core/Debugger.cpp2
3 files changed, 21 insertions, 7 deletions
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index 17ed2fd7689..f8de19810b1 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -25,7 +25,7 @@ using namespace lldb_private;
//----------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------
-Communication::Communication(const char *name) :
+Communication::Communication(const char *name, bool close_on_eof) :
Broadcaster (name),
m_connection_ap (),
m_read_thread (LLDB_INVALID_HOST_THREAD),
@@ -33,7 +33,8 @@ Communication::Communication(const char *name) :
m_bytes(),
m_bytes_mutex (Mutex::eMutexTypeRecursive),
m_callback (NULL),
- m_callback_baton (NULL)
+ m_callback_baton (NULL),
+ m_close_on_eof (close_on_eof)
{
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
@@ -265,7 +266,8 @@ Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broad
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
"%p Communication::AppendBytesToCache (src = %p, src_len = %zu, broadcast = %i)",
this, bytes, len, broadcast);
- if (bytes == NULL || len == 0)
+ if ((bytes == NULL || len == 0)
+ && (status != eConnectionStatusEndOfFile))
return;
if (m_callback)
{
@@ -289,6 +291,11 @@ Communication::ReadFromConnection (void *dst, size_t dst_len, ConnectionStatus &
return 0;
}
+bool
+Communication::CloseOnEOF ()
+{
+ return m_close_on_eof;
+}
bool
Communication::ReadThreadIsRunning ()
@@ -320,14 +327,21 @@ Communication::ReadThread (void *p)
size_t bytes_read = comm->ReadFromConnection (buf, sizeof(buf), status, &error);
if (bytes_read > 0)
comm->AppendBytesToCache (buf, bytes_read, true, status);
+ else if ((bytes_read == 0)
+ && status == eConnectionStatusEndOfFile)
+ {
+ if (comm->CloseOnEOF ())
+ comm->Disconnect ();
+ comm->AppendBytesToCache (buf, bytes_read, true, status);
+ }
}
switch (status)
{
case eConnectionStatusSuccess:
+ case eConnectionStatusEndOfFile:
break;
- case eConnectionStatusEndOfFile:
case eConnectionStatusNoConnection: // No connection
case eConnectionStatusLostConnection: // Lost connection while connected to a valid connection
done = true;
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp
index 96d70bc1012..c333d06b176 100644
--- a/lldb/source/Core/ConnectionFileDescriptor.cpp
+++ b/lldb/source/Core/ConnectionFileDescriptor.cpp
@@ -156,8 +156,8 @@ ConnectionFileDescriptor::Read (void *dst, size_t dst_len, ConnectionStatus &sta
ssize_t bytes_read = ::read (m_fd, dst, dst_len);
if (bytes_read == 0)
{
- error.SetErrorStringWithFormat("End-of-file.\n");
- status = eConnectionStatusLostConnection;
+ error.Clear(); // End-of-file. Do not automatically close; pass along for the end-of-file handlers.
+ status = eConnectionStatusEndOfFile;
}
else if (bytes_read < 0)
{
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index a06095fa80b..8884c3c95b1 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -166,7 +166,7 @@ Debugger::FindTargetWithProcessID (lldb::pid_t pid)
Debugger::Debugger () :
UserID (g_unique_id++),
DebuggerInstanceSettings (*GetSettingsController()),
- m_input_comm("debugger.input"),
+ m_input_comm("debugger.input", false),
m_input_file (),
m_output_file (),
m_error_file (),
OpenPOWER on IntegriCloud