Fixed the delay that was happening when quitting lldb from the command line. We weren't initializing the command pipes when constructing a ConnectionFileDescriptor with a file descriptor.

llvm-svn: 161533
This commit is contained in:
Greg Clayton 2012-08-08 22:27:52 +00:00
parent bf1ac4bdc3
commit fcde4fad2b
2 changed files with 35 additions and 34 deletions

View File

@ -72,10 +72,10 @@ public:
protected:
void
InitializeCommandFileDescriptor ();
OpenCommandPipe ();
void
CloseCommandFileDescriptor ();
CloseCommandPipe ();
lldb::ConnectionStatus
BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
@ -110,13 +110,13 @@ protected:
FDType m_fd_send_type;
FDType m_fd_recv_type;
SocketAddress m_udp_send_sockaddr;
bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
uint32_t m_socket_timeout_usec;
int m_command_fd_send; // A pipe that we select on the reading end of along with
int m_command_fd_receive; // m_fd_recv so we can force ourselves out of the select.
int m_pipe_read; // A pipe that we select on the reading end of along with
int m_pipe_write; // m_fd_recv so we can force ourselves out of the select.
Mutex m_mutex;
bool m_shutting_down; // This marks that we are shutting down so if we get woken up from BytesAvailable
// to disconnect, we won't try to read again.
bool m_shutting_down; // This marks that we are shutting down so if we get woken up from BytesAvailable
// to disconnect, we won't try to read again.
static in_port_t
GetSocketPort (int fd);

View File

@ -75,8 +75,8 @@ ConnectionFileDescriptor::ConnectionFileDescriptor () :
m_udp_send_sockaddr (),
m_should_close_fd (false),
m_socket_timeout_usec(0),
m_command_fd_send(-1),
m_command_fd_receive(-1),
m_pipe_read(-1),
m_pipe_write(-1),
m_mutex (Mutex::eMutexTypeRecursive),
m_shutting_down (false)
{
@ -94,14 +94,15 @@ ConnectionFileDescriptor::ConnectionFileDescriptor (int fd, bool owns_fd) :
m_udp_send_sockaddr (),
m_should_close_fd (owns_fd),
m_socket_timeout_usec(0),
m_command_fd_send(-1),
m_command_fd_receive(-1),
m_pipe_read(-1),
m_pipe_write(-1),
m_mutex (Mutex::eMutexTypeRecursive),
m_shutting_down (false)
{
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT));
if (log)
log->Printf ("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = %i, owns_fd = %i)", this, fd, owns_fd);
OpenCommandPipe ();
}
@ -111,13 +112,13 @@ ConnectionFileDescriptor::~ConnectionFileDescriptor ()
if (log)
log->Printf ("%p ConnectionFileDescriptor::~ConnectionFileDescriptor ()", this);
Disconnect (NULL);
CloseCommandFileDescriptor ();
CloseCommandPipe ();
}
void
ConnectionFileDescriptor::InitializeCommandFileDescriptor ()
ConnectionFileDescriptor::OpenCommandPipe ()
{
CloseCommandFileDescriptor();
CloseCommandPipe();
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT));
// Make the command file descriptor here:
@ -132,24 +133,24 @@ ConnectionFileDescriptor::InitializeCommandFileDescriptor ()
}
else
{
m_command_fd_receive = filedes[0];
m_command_fd_send = filedes[1];
m_pipe_read = filedes[0];
m_pipe_write = filedes[1];
}
}
void
ConnectionFileDescriptor::CloseCommandFileDescriptor ()
ConnectionFileDescriptor::CloseCommandPipe ()
{
if (m_command_fd_receive != -1)
if (m_pipe_read != -1)
{
close (m_command_fd_receive);
m_command_fd_receive = -1;
close (m_pipe_read);
m_pipe_read = -1;
}
if (m_command_fd_send != -1)
if (m_pipe_write != -1)
{
close (m_command_fd_send);
m_command_fd_send = -1;
close (m_pipe_write);
m_pipe_write = -1;
}
}
@ -167,7 +168,7 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
if (log)
log->Printf ("%p ConnectionFileDescriptor::Connect (url = '%s')", this, s);
InitializeCommandFileDescriptor();
OpenCommandPipe();
if (s && s[0])
{
@ -309,11 +310,11 @@ ConnectionFileDescriptor::Disconnect (Error *error_ptr)
if (!got_lock)
{
if (m_command_fd_send != -1 )
if (m_pipe_write != -1 )
{
write (m_command_fd_send, "q", 1);
close (m_command_fd_send);
m_command_fd_send = -1;
write (m_pipe_write, "q", 1);
close (m_pipe_write);
m_pipe_write = -1;
}
locker.Lock (m_mutex);
}
@ -613,14 +614,14 @@ ConnectionFileDescriptor::BytesAvailable (uint32_t timeout_usec, Error *error_pt
tv_ptr = &tv;
}
while (IsConnected())
while (m_fd_recv >= 0)
{
fd_set read_fds;
FD_ZERO (&read_fds);
FD_SET (m_fd_recv, &read_fds);
if (m_command_fd_receive != -1)
FD_SET (m_command_fd_receive, &read_fds);
int nfds = (m_fd_recv > m_command_fd_receive ? m_fd_recv : m_command_fd_receive) + 1;
if (m_pipe_read != -1)
FD_SET (m_pipe_read, &read_fds);
int nfds = std::max<int>(m_fd_recv, m_pipe_read) + 1;
Error error;
@ -668,7 +669,7 @@ ConnectionFileDescriptor::BytesAvailable (uint32_t timeout_usec, Error *error_pt
}
else if (num_set_fds > 0)
{
if (m_command_fd_receive != -1 && FD_ISSET(m_command_fd_receive, &read_fds))
if (m_pipe_read != -1 && FD_ISSET(m_pipe_read, &read_fds))
{
// We got a command to exit. Read the data from that pipe:
char buffer[16];
@ -676,7 +677,7 @@ ConnectionFileDescriptor::BytesAvailable (uint32_t timeout_usec, Error *error_pt
do
{
bytes_read = ::read (m_command_fd_receive, buffer, sizeof(buffer));
bytes_read = ::read (m_pipe_read, buffer, sizeof(buffer));
} while (bytes_read < 0 && errno == EINTR);
assert (bytes_read == 1 && buffer[0] == 'q');