diff options
| author | Oleksiy Vyalov <ovyalov@google.com> | 2015-10-27 17:32:01 +0000 |
|---|---|---|
| committer | Oleksiy Vyalov <ovyalov@google.com> | 2015-10-27 17:32:01 +0000 |
| commit | db4d9865b42584d6d4ebb31e899e5c0fa85f1624 (patch) | |
| tree | 9d9ebf4a9be5e0b13635964e9239505836fe7c85 /lldb/source/Host/common | |
| parent | d5cc99c3dd8a5f7649e0a43bce48d15b38121dfb (diff) | |
| download | bcm5719-llvm-db4d9865b42584d6d4ebb31e899e5c0fa85f1624.tar.gz bcm5719-llvm-db4d9865b42584d6d4ebb31e899e5c0fa85f1624.zip | |
Add Socket::Create factory method which uses socket protocol to find an appropriate implementation class.
http://reviews.llvm.org/D14085
llvm-svn: 251417
Diffstat (limited to 'lldb/source/Host/common')
| -rw-r--r-- | lldb/source/Host/common/Socket.cpp | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 3cabcf6a543..f7023de7d97 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -86,6 +86,41 @@ Socket::~Socket() Close(); } +std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol, bool child_processes_inherit, Error &error) +{ + error.Clear(); + + std::unique_ptr<Socket> socket_up; + switch (protocol) + { + case ProtocolTcp: + socket_up.reset(new TCPSocket(child_processes_inherit, error)); + break; + case ProtocolUdp: + socket_up.reset(new UDPSocket(child_processes_inherit, error)); + break; + case ProtocolUnixDomain: +#ifndef LLDB_DISABLE_POSIX + socket_up.reset(new DomainSocket(child_processes_inherit, error)); +#else + error.SetErrorString("Unix domain sockets are not supported on this platform."); +#endif + break; + case ProtocolUnixAbstract: +#ifdef __linux__ + socket_up.reset(new AbstractSocket(child_processes_inherit, error)); +#else + error.SetErrorString("Abstract domain sockets are not supported on this platform."); +#endif + break; + } + + if (error.Fail()) + socket_up.reset(); + + return socket_up; +} + Error Socket::TcpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket) { Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION)); @@ -93,7 +128,7 @@ Error Socket::TcpConnect(llvm::StringRef host_and_port, bool child_processes_inh log->Printf ("Socket::%s (host/port = %s)", __FUNCTION__, host_and_port.data()); Error error; - std::unique_ptr<TCPSocket> connect_socket(new TCPSocket(child_processes_inherit, error)); + std::unique_ptr<Socket> connect_socket(Create(ProtocolTcp, child_processes_inherit, error)); if (error.Fail()) return error; @@ -161,25 +196,21 @@ Error Socket::UdpConnect(llvm::StringRef host_and_port, bool child_processes_inh Error Socket::UnixDomainConnect(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) { Error error; -#ifndef LLDB_DISABLE_POSIX - std::unique_ptr<DomainSocket> connect_socket(new DomainSocket(child_processes_inherit, error)); + std::unique_ptr<Socket> connect_socket(Create(ProtocolUnixDomain, child_processes_inherit, error)); if (error.Fail()) return error; error = connect_socket->Connect(name); if (error.Success()) socket = connect_socket.release(); -#else - error.SetErrorString("Unix domain sockets are not supported on this platform."); -#endif + return error; } Error Socket::UnixDomainAccept(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) { Error error; -#ifndef LLDB_DISABLE_POSIX - std::unique_ptr<DomainSocket> listen_socket(new DomainSocket(child_processes_inherit, error)); + std::unique_ptr<Socket> listen_socket(Create(ProtocolUnixDomain, child_processes_inherit, error)); if (error.Fail()) return error; @@ -188,9 +219,6 @@ Error Socket::UnixDomainAccept(llvm::StringRef name, bool child_processes_inheri return error; error = listen_socket->Accept(name, child_processes_inherit, socket); -#else - error.SetErrorString("Unix domain sockets are not supported on this platform."); -#endif return error; } @@ -198,17 +226,13 @@ Error Socket::UnixAbstractConnect(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) { Error error; -#ifdef __linux__ - std::unique_ptr<Socket> connect_socket(new AbstractSocket(child_processes_inherit, error)); + std::unique_ptr<Socket> connect_socket(Create(ProtocolUnixAbstract, child_processes_inherit, error)); if (error.Fail()) return error; error = connect_socket->Connect(name); if (error.Success()) socket = connect_socket.release(); -#else - error.SetErrorString("Abstract domain sockets are not supported on this platform."); -#endif return error; } @@ -216,8 +240,7 @@ Error Socket::UnixAbstractAccept(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) { Error error; -#ifdef __linux__ - std::unique_ptr<Socket> listen_socket(new AbstractSocket(child_processes_inherit, error)); + std::unique_ptr<Socket> listen_socket(Create(ProtocolUnixAbstract,child_processes_inherit, error)); if (error.Fail()) return error; @@ -226,9 +249,6 @@ Socket::UnixAbstractAccept(llvm::StringRef name, bool child_processes_inherit, S return error; error = listen_socket->Accept(name, child_processes_inherit, socket); -#else - error.SetErrorString("Abstract domain sockets are not supported on this platform."); -#endif return error; } |

