[Lldb-commits] [lldb] r226362 - Added Connection::GetURI()
Vince Harron
vharron at google.com
Fri Jan 16 18:20:29 PST 2015
Author: vharron
Date: Fri Jan 16 20:20:29 2015
New Revision: 226362
URL: http://llvm.org/viewvc/llvm-project?rev=226362&view=rev
Log:
Added Connection::GetURI()
This function returns a URI of the resource that the connection is connected to. This is especially important for connections established by accepting a connection from a remote host.
Also added implementations for ConnectionMachPort, ConnectionSharedMemory,
Also fixed up some documentation in Connection::Write
Renamed ConnectionFileDescriptorPosix::SocketListen to ConnectionFileDescriptorPosix::SocketListenAndAccept
Fixed a log message in Socket.cpp
Differential Review: http://reviews.llvm.org/D7026
Modified:
lldb/trunk/include/lldb/Core/Connection.h
lldb/trunk/include/lldb/Core/ConnectionMachPort.h
lldb/trunk/include/lldb/Core/ConnectionSharedMemory.h
lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
lldb/trunk/include/lldb/Host/windows/ConnectionGenericFileWindows.h
lldb/trunk/source/Core/ConnectionMachPort.cpp
lldb/trunk/source/Core/ConnectionSharedMemory.cpp
lldb/trunk/source/Host/common/Socket.cpp
lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp
lldb/trunk/source/Host/windows/ConnectionGenericFileWindows.cpp
Modified: lldb/trunk/include/lldb/Core/Connection.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Connection.h?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Connection.h (original)
+++ lldb/trunk/include/lldb/Core/Connection.h Fri Jan 16 20:20:29 2015
@@ -133,13 +133,13 @@ public:
///
/// Subclasses must override this function.
///
- /// @param[in] src
- /// A source buffer that must be at least \a src_len bytes
+ /// @param[in] dst
+ /// A desination buffer that must be at least \a dst_len bytes
/// long.
///
- /// @param[in] src_len
+ /// @param[in] dst_len
/// The number of bytes to attempt to write, and also the
- /// number of bytes are currently available in \a src.
+ /// number of bytes are currently available in \a dst.
///
/// @param[out] error_ptr
/// A pointer to an error object that should be given an
@@ -150,7 +150,18 @@ public:
/// The number of bytes actually Written.
//------------------------------------------------------------------
virtual size_t
- Write (const void *buffer, size_t length, lldb::ConnectionStatus &status, Error *error_ptr) = 0;
+ Write (const void *dst, size_t dst_len, lldb::ConnectionStatus &status, Error *error_ptr) = 0;
+
+ //------------------------------------------------------------------
+ /// Returns a URI that describes this connection object
+ ///
+ /// Subclasses may override this function.
+ ///
+ /// @return
+ /// Returns URI or an empty string if disconnecteds
+ //------------------------------------------------------------------
+ virtual std::string
+ GetURI() = 0;
private:
//------------------------------------------------------------------
Modified: lldb/trunk/include/lldb/Core/ConnectionMachPort.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConnectionMachPort.h?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConnectionMachPort.h (original)
+++ lldb/trunk/include/lldb/Core/ConnectionMachPort.h Fri Jan 16 20:20:29 2015
@@ -56,6 +56,9 @@ public:
lldb::ConnectionStatus &status,
lldb_private::Error *error_ptr);
+ virtual std::string
+ GetURI();
+
lldb::ConnectionStatus
BootstrapCheckIn (const char *port_name,
lldb_private::Error *error_ptr);
@@ -83,6 +86,7 @@ protected:
mach_port_t m_port;
private:
+ std::string m_uri;
DISALLOW_COPY_AND_ASSIGN (ConnectionMachPort);
Modified: lldb/trunk/include/lldb/Core/ConnectionSharedMemory.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConnectionSharedMemory.h?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConnectionSharedMemory.h (original)
+++ lldb/trunk/include/lldb/Core/ConnectionSharedMemory.h Fri Jan 16 20:20:29 2015
@@ -53,6 +53,9 @@ public:
virtual size_t
Write (const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr);
+ virtual std::string
+ GetURI();
+
lldb::ConnectionStatus
Open (bool create, const char *name, size_t size, Error *error_ptr);
Modified: lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h (original)
+++ lldb/trunk/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h Fri Jan 16 20:20:29 2015
@@ -50,6 +50,8 @@ class ConnectionFileDescriptor : public
virtual size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr);
+ virtual std::string GetURI();
+
lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec, Error *error_ptr);
bool InterruptRead();
@@ -75,7 +77,7 @@ class ConnectionFileDescriptor : public
void CloseCommandPipe();
- lldb::ConnectionStatus SocketListen(const char *host_and_port, Error *error_ptr);
+ lldb::ConnectionStatus SocketListenAndAccept(const char *host_and_port, Error *error_ptr);
lldb::ConnectionStatus ConnectTCP(const char *host_and_port, Error *error_ptr);
@@ -99,6 +101,8 @@ class ConnectionFileDescriptor : public
bool m_waiting_for_accept;
bool m_child_processes_inherit;
+ std::string m_uri;
+
private:
DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor);
};
Modified: lldb/trunk/include/lldb/Host/windows/ConnectionGenericFileWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/ConnectionGenericFileWindows.h?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/ConnectionGenericFileWindows.h (original)
+++ lldb/trunk/include/lldb/Host/windows/ConnectionGenericFileWindows.h Fri Jan 16 20:20:29 2015
@@ -38,6 +38,8 @@ class ConnectionGenericFile : public lld
virtual size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr);
+ virtual std::string GetURI();
+
bool InterruptRead();
protected:
@@ -57,6 +59,8 @@ class ConnectionGenericFile : public lld
void InitializeEventHandles();
void IncrementFilePointer(DWORD amount);
+ std::string m_uri;
+
DISALLOW_COPY_AND_ASSIGN(ConnectionGenericFile);
};
}
Modified: lldb/trunk/source/Core/ConnectionMachPort.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionMachPort.cpp?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConnectionMachPort.cpp (original)
+++ lldb/trunk/source/Core/ConnectionMachPort.cpp Fri Jan 16 20:20:29 2015
@@ -107,6 +107,7 @@ ConnectionMachPort::Connect (const char
{
if (error_ptr)
error_ptr->Clear();
+ m_uri.assign(s);
}
else
{
@@ -209,6 +210,7 @@ ConnectionMachPort::Disconnect (Error *e
error_ptr->SetError (kret, eErrorTypeMachKernel);
m_port = MACH_PORT_TYPE_NONE;
}
+ m_uri.clear();
return eConnectionStatusSuccess;
}
@@ -256,6 +258,12 @@ ConnectionMachPort::Write (const void *s
return 0;
}
+std::string
+ConnectionMachPort::GetURI()
+{
+ return m_uri;
+}
+
ConnectionStatus
ConnectionMachPort::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
{
Modified: lldb/trunk/source/Core/ConnectionSharedMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionSharedMemory.cpp?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConnectionSharedMemory.cpp (original)
+++ lldb/trunk/source/Core/ConnectionSharedMemory.cpp Fri Jan 16 20:20:29 2015
@@ -107,6 +107,13 @@ ConnectionSharedMemory::Write (const voi
return 0;
}
+std::string
+ConnectionSharedMemory::GetURI()
+{
+ // TODO: fix when Connect is fixed?
+ return "";
+}
+
ConnectionStatus
ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
{
Modified: lldb/trunk/source/Host/common/Socket.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Socket.cpp?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Socket.cpp (original)
+++ lldb/trunk/source/Host/common/Socket.cpp Fri Jan 16 20:20:29 2015
@@ -190,7 +190,7 @@ Error Socket::TcpListen(llvm::StringRef
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
- log->Printf ("ConnectionFileDescriptor::SocketListen (%s)", host_and_port.data());
+ log->Printf ("Socket::TcpListen (%s)", host_and_port.data());
std::string host_str;
std::string port_str;
Modified: lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp Fri Jan 16 20:20:29 2015
@@ -42,6 +42,7 @@
#include "lldb/lldb-private-log.h"
#include "lldb/Core/Communication.h"
#include "lldb/Core/Log.h"
+#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/Socket.h"
@@ -143,7 +144,7 @@ ConnectionFileDescriptor::Connect(const
if (strstr(s, "listen://") == s)
{
// listen://HOST:PORT
- return SocketListen(s + strlen("listen://"), error_ptr);
+ return SocketListenAndAccept(s + strlen("listen://"), error_ptr);
}
else if (strstr(s, "accept://") == s)
{
@@ -220,6 +221,7 @@ ConnectionFileDescriptor::Connect(const
m_read_sp.reset(new File(fd, false));
m_write_sp.reset(new File(fd, false));
}
+ m_uri.assign(s);
return eConnectionStatusSuccess;
}
}
@@ -352,6 +354,7 @@ ConnectionFileDescriptor::Disconnect(Err
if (error_ptr)
*error_ptr = error.Fail() ? error : error2;
+ m_uri.clear();
m_shutting_down = false;
return status;
}
@@ -511,6 +514,12 @@ ConnectionFileDescriptor::Write(const vo
return bytes_sent;
}
+std::string
+ConnectionFileDescriptor::GetURI()
+{
+ return m_uri;
+}
+
// This ConnectionFileDescriptor::BytesAvailable() uses select().
//
// PROS:
@@ -701,7 +710,12 @@ ConnectionFileDescriptor::NamedSocketAcc
*error_ptr = error;
m_write_sp.reset(socket);
m_read_sp = m_write_sp;
- return (error.Success()) ? eConnectionStatusSuccess : eConnectionStatusError;
+ if (error.Fail())
+ {
+ return eConnectionStatusError;
+ }
+ m_uri.assign(socket_name);
+ return eConnectionStatusSuccess;
}
ConnectionStatus
@@ -713,11 +727,16 @@ ConnectionFileDescriptor::NamedSocketCon
*error_ptr = error;
m_write_sp.reset(socket);
m_read_sp = m_write_sp;
- return (error.Success()) ? eConnectionStatusSuccess : eConnectionStatusError;
+ if (error.Fail())
+ {
+ return eConnectionStatusError;
+ }
+ m_uri.assign(socket_name);
+ return eConnectionStatusSuccess;
}
ConnectionStatus
-ConnectionFileDescriptor::SocketListen(const char *s, Error *error_ptr)
+ConnectionFileDescriptor::SocketListenAndAccept(const char *s, Error *error_ptr)
{
m_port_predicate.SetValue(0, eBroadcastNever);
@@ -742,7 +761,14 @@ ConnectionFileDescriptor::SocketListen(c
m_write_sp.reset(socket);
m_read_sp = m_write_sp;
- return (error.Success()) ? eConnectionStatusSuccess : eConnectionStatusError;
+ if (error.Fail())
+ {
+ return eConnectionStatusError;
+ }
+ StreamString strm;
+ strm.Printf("connect://%s:%u",socket->GetRemoteIPAddress().c_str(), socket->GetRemotePortNumber());
+ m_uri.swap(strm.GetString());
+ return eConnectionStatusSuccess;
}
ConnectionStatus
@@ -754,7 +780,12 @@ ConnectionFileDescriptor::ConnectTCP(con
*error_ptr = error;
m_write_sp.reset(socket);
m_read_sp = m_write_sp;
- return (error.Success()) ? eConnectionStatusSuccess : eConnectionStatusError;
+ if (error.Fail())
+ {
+ return eConnectionStatusError;
+ }
+ m_uri.assign(s);
+ return eConnectionStatusSuccess;
}
ConnectionStatus
@@ -767,7 +798,12 @@ ConnectionFileDescriptor::ConnectUDP(con
*error_ptr = error;
m_write_sp.reset(send_socket);
m_read_sp.reset(recv_socket);
- return (error.Success()) ? eConnectionStatusSuccess : eConnectionStatusError;
+ if (error.Fail())
+ {
+ return eConnectionStatusError;
+ }
+ m_uri.assign(s);
+ return eConnectionStatusSuccess;
}
uint16_t
Modified: lldb/trunk/source/Host/windows/ConnectionGenericFileWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/ConnectionGenericFileWindows.cpp?rev=226362&r1=226361&r2=226362&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/ConnectionGenericFileWindows.cpp (original)
+++ lldb/trunk/source/Host/windows/ConnectionGenericFileWindows.cpp Fri Jan 16 20:20:29 2015
@@ -147,6 +147,7 @@ ConnectionGenericFile::Connect(const cha
}
m_owns_file = true;
+ m_uri.assign(s);
return eConnectionStatusSuccess;
}
@@ -175,6 +176,7 @@ ConnectionGenericFile::Disconnect(Error
::ZeroMemory(&m_file_position, sizeof(m_file_position));
m_owns_file = false;
+ m_uri.clear();
return eConnectionStatusSuccess;
}
@@ -328,6 +330,12 @@ finish:
return return_info.GetBytes();
}
+std::string
+ConnectionGenericFile::GetURI()
+{
+ return m_uri;
+}
+
bool
ConnectionGenericFile::InterruptRead()
{
More information about the lldb-commits
mailing list