diff options
Diffstat (limited to 'source/Host/posix')
-rw-r--r-- | source/Host/posix/ConnectionFileDescriptorPosix.cpp | 53 | ||||
-rw-r--r-- | source/Host/posix/PipePosix.cpp | 35 |
2 files changed, 80 insertions, 8 deletions
diff --git a/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/source/Host/posix/ConnectionFileDescriptorPosix.cpp index 38ddc0a492201..fe70c33bf5ae2 100644 --- a/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -19,6 +19,7 @@ #include "lldb/Host/IOObject.h" #include "lldb/Host/SocketAddress.h" #include "lldb/Host/Socket.h" +#include "lldb/Host/StringConvert.h" // C Includes #include <errno.h> @@ -41,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" @@ -142,7 +144,7 @@ ConnectionFileDescriptor::Connect(const char *s, Error *error_ptr) 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) { @@ -173,7 +175,7 @@ ConnectionFileDescriptor::Connect(const char *s, Error *error_ptr) // that is already opened (possibly from a service or other source). s += strlen("fd://"); bool success = false; - int fd = Args::StringToSInt32(s, -1, 0, &success); + int fd = StringConvert::ToSInt32(s, -1, 0, &success); if (success) { @@ -219,6 +221,7 @@ ConnectionFileDescriptor::Connect(const char *s, Error *error_ptr) m_read_sp.reset(new File(fd, false)); m_write_sp.reset(new File(fd, false)); } + m_uri.assign(s); return eConnectionStatusSuccess; } } @@ -351,6 +354,7 @@ ConnectionFileDescriptor::Disconnect(Error *error_ptr) if (error_ptr) *error_ptr = error.Fail() ? error : error2; + m_uri.clear(); m_shutting_down = false; return status; } @@ -510,6 +514,12 @@ ConnectionFileDescriptor::Write(const void *src, size_t src_len, ConnectionStatu return bytes_sent; } +std::string +ConnectionFileDescriptor::GetURI() +{ + return m_uri; +} + // This ConnectionFileDescriptor::BytesAvailable() uses select(). // // PROS: @@ -700,7 +710,12 @@ ConnectionFileDescriptor::NamedSocketAccept(const char *socket_name, Error *erro *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 @@ -712,11 +727,16 @@ ConnectionFileDescriptor::NamedSocketConnect(const char *socket_name, Error *err *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); @@ -741,7 +761,14 @@ ConnectionFileDescriptor::SocketListen(const char *s, Error *error_ptr) 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 @@ -753,7 +780,12 @@ ConnectionFileDescriptor::ConnectTCP(const char *s, Error *error_ptr) *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 @@ -766,7 +798,12 @@ ConnectionFileDescriptor::ConnectUDP(const char *s, Error *error_ptr) *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 diff --git a/source/Host/posix/PipePosix.cpp b/source/Host/posix/PipePosix.cpp index 02838ec5124e7..1650f1e7979b2 100644 --- a/source/Host/posix/PipePosix.cpp +++ b/source/Host/posix/PipePosix.cpp @@ -9,12 +9,16 @@ #include "lldb/Host/posix/PipePosix.h" #include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/FileSystem.h" #include <functional> #include <thread> #include <errno.h> #include <fcntl.h> +#include <limits.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> @@ -183,6 +187,37 @@ PipePosix::CreateNew(llvm::StringRef name, bool child_process_inherit) } Error +PipePosix::CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name) +{ + llvm::SmallString<PATH_MAX> named_pipe_path; + llvm::SmallString<PATH_MAX> pipe_spec((prefix + ".%%%%%%").str()); + FileSpec tmpdir_file_spec; + tmpdir_file_spec.Clear(); + if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec)) + { + tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str()); + } + else + { + tmpdir_file_spec.AppendPathComponent("/tmp"); + tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str()); + } + + // It's possible that another process creates the target path after we've + // verified it's available but before we create it, in which case we + // should try again. + Error error; + do { + llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath().c_str(), named_pipe_path); + error = CreateNew(named_pipe_path, child_process_inherit); + } while (error.GetError() == EEXIST); + + if (error.Success()) + name = named_pipe_path; + return error; +} + +Error PipePosix::OpenAsReader(llvm::StringRef name, bool child_process_inherit) { if (CanRead() || CanWrite()) |