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
llvm-svn: 226362
///
/// 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
/// 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:
//------------------------------------------------------------------
lldb::ConnectionStatus &status,
lldb_private::Error *error_ptr);
+ virtual std::string
+ GetURI();
+
lldb::ConnectionStatus
BootstrapCheckIn (const char *port_name,
lldb_private::Error *error_ptr);
mach_port_t m_port;
private:
+ std::string m_uri;
DISALLOW_COPY_AND_ASSIGN (ConnectionMachPort);
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);
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();
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);
bool m_waiting_for_accept;
bool m_child_processes_inherit;
+ std::string m_uri;
+
private:
DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor);
};
virtual size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr);
+ virtual std::string GetURI();
+
bool InterruptRead();
protected:
void InitializeEventHandles();
void IncrementFilePointer(DWORD amount);
+ std::string m_uri;
+
DISALLOW_COPY_AND_ASSIGN(ConnectionGenericFile);
};
}
{
if (error_ptr)
error_ptr->Clear();
+ m_uri.assign(s);
}
else
{
error_ptr->SetError (kret, eErrorTypeMachKernel);
m_port = MACH_PORT_TYPE_NONE;
}
+ m_uri.clear();
return eConnectionStatusSuccess;
}
return 0;
}
+std::string
+ConnectionMachPort::GetURI()
+{
+ return m_uri;
+}
+
ConnectionStatus
ConnectionMachPort::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
{
return 0;
}
+std::string
+ConnectionSharedMemory::GetURI()
+{
+ // TODO: fix when Connect is fixed?
+ return "";
+}
+
ConnectionStatus
ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
{
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;
#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"
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)
{
m_read_sp.reset(new File(fd, false));
m_write_sp.reset(new File(fd, false));
}
+ m_uri.assign(s);
return eConnectionStatusSuccess;
}
}
if (error_ptr)
*error_ptr = error.Fail() ? error : error2;
+ m_uri.clear();
m_shutting_down = false;
return status;
}
return bytes_sent;
}
+std::string
+ConnectionFileDescriptor::GetURI()
+{
+ return m_uri;
+}
+
// This ConnectionFileDescriptor::BytesAvailable() uses select().
//
// PROS:
*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
*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);
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
*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
*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
}
m_owns_file = true;
+ m_uri.assign(s);
return eConnectionStatusSuccess;
}
::ZeroMemory(&m_file_position, sizeof(m_file_position));
m_owns_file = false;
+ m_uri.clear();
return eConnectionStatusSuccess;
}
return return_info.GetBytes();
}
+std::string
+ConnectionGenericFile::GetURI()
+{
+ return m_uri;
+}
+
bool
ConnectionGenericFile::InterruptRead()
{