summaryrefslogtreecommitdiff
path: root/include/lldb/Host/Socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Host/Socket.h')
-rw-r--r--include/lldb/Host/Socket.h63
1 files changed, 30 insertions, 33 deletions
diff --git a/include/lldb/Host/Socket.h b/include/lldb/Host/Socket.h
index f4599b5ab87b3..a38b42f817c60 100644
--- a/include/lldb/Host/Socket.h
+++ b/include/lldb/Host/Socket.h
@@ -10,6 +10,7 @@
#ifndef liblldb_Host_Socket_h_
#define liblldb_Host_Socket_h_
+#include <memory>
#include <string>
#include "lldb/lldb-private.h"
@@ -45,13 +46,19 @@ public:
{
ProtocolTcp,
ProtocolUdp,
- ProtocolUnixDomain
+ ProtocolUnixDomain,
+ ProtocolUnixAbstract
} SocketProtocol;
static const NativeSocket kInvalidSocketValue;
- Socket(NativeSocket socket, SocketProtocol protocol, bool should_close);
- ~Socket();
+ ~Socket() override;
+
+ static std::unique_ptr<Socket> Create(const SocketProtocol protocol, bool child_processes_inherit, Error &error);
+
+ virtual Error Connect(llvm::StringRef name) = 0;
+ virtual Error Listen(llvm::StringRef name, int backlog) = 0;
+ virtual Error Accept(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) = 0;
// Initialize a Tcp Socket object in listening mode. listen and accept are implemented
// separately because the caller may wish to manipulate or query the socket after it is
@@ -66,43 +73,23 @@ public:
static Error UdpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&send_socket, Socket *&recv_socket);
static Error UnixDomainConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket);
static Error UnixDomainAccept(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket);
-
- // Blocks on a listening socket until a connection is received. This method assumes that
- // |this->m_socket| is a listening socket, created via either TcpListen() or via the native
- // constructor that takes a NativeSocket, which itself was created via a call to |listen()|
- Error BlockingAccept(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket);
+ static Error UnixAbstractConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket);
+ static Error UnixAbstractAccept(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket);
int GetOption (int level, int option_name, int &option_value);
int SetOption (int level, int option_name, int option_value);
- // returns port number or 0 if error
- static uint16_t GetLocalPortNumber (const NativeSocket& socket);
-
- // returns port number or 0 if error
- uint16_t GetLocalPortNumber () const;
-
- // returns ip address string or empty string if error
- std::string GetLocalIPAddress () const;
-
- // must be connected
- // returns port number or 0 if error
- uint16_t GetRemotePortNumber () const;
-
- // must be connected
- // returns ip address string or empty string if error
- std::string GetRemoteIPAddress () const;
-
NativeSocket GetNativeSocket () const { return m_socket; }
SocketProtocol GetSocketProtocol () const { return m_protocol; }
- virtual Error Read (void *buf, size_t &num_bytes);
- virtual Error Write (const void *buf, size_t &num_bytes);
+ Error Read (void *buf, size_t &num_bytes) override;
+ Error Write (const void *buf, size_t &num_bytes) override;
virtual Error PreDisconnect ();
- virtual Error Close ();
+ Error Close() override;
- virtual bool IsValid () const { return m_socket != kInvalidSocketValue; }
- virtual WaitableHandle GetWaitableHandle ();
+ bool IsValid () const override { return m_socket != kInvalidSocketValue; }
+ WaitableHandle GetWaitableHandle () override;
static bool
DecodeHostAndPort (llvm::StringRef host_and_port,
@@ -112,10 +99,20 @@ public:
Error *error_ptr);
protected:
+ Socket(NativeSocket socket, SocketProtocol protocol, bool should_close);
+
+ virtual size_t Send(const void *buf, const size_t num_bytes);
+
+ static void SetLastError(Error &error);
+ static NativeSocket CreateSocket(
+ const int domain, const int type, const int protocol, bool child_processes_inherit, Error& error);
+ static NativeSocket AcceptSocket(
+ NativeSocket sockfd, struct sockaddr *addr, socklen_t *addrlen, bool child_processes_inherit, Error& error);
+
SocketProtocol m_protocol;
NativeSocket m_socket;
- SocketAddress m_udp_send_sockaddr; // Send address used for UDP connections.
};
-}
-#endif
+} // namespace lldb_private
+
+#endif // liblldb_Host_Socket_h_