11#include "lldb/Host/Config.h"
17#include <sys/socket.h>
26static const int kType = SOCK_DGRAM;
35 :
Socket(ProtocolUdp, should_close, child_processes_inherit) {}
38 return ::sendto(
m_socket,
static_cast<const char *
>(buf), num_bytes, 0,
54llvm::Expected<std::unique_ptr<UDPSocket>>
56 std::unique_ptr<UDPSocket> socket;
59 LLDB_LOG(log,
"host/port = {0}", name);
64 return host_port.takeError();
69 struct addrinfo hints;
70 struct addrinfo *service_info_list =
nullptr;
72 ::memset(&hints, 0,
sizeof(hints));
74 hints.ai_socktype =
kType;
75 int err = ::getaddrinfo(host_port->hostname.c_str(), std::to_string(host_port->port).c_str(), &hints,
78 error.SetErrorStringWithFormat(
79#
if defined(_WIN32) && defined(UNICODE)
80 "getaddrinfo(%s, %d, &hints, &info) returned error %i (%S)",
82 "getaddrinfo(%s, %d, &hints, &info) returned error %i (%s)",
84 host_port->hostname.c_str(), host_port->port, err, gai_strerror(err));
85 return error.ToError();
88 for (
struct addrinfo *service_info_ptr = service_info_list;
89 service_info_ptr !=
nullptr;
90 service_info_ptr = service_info_ptr->ai_next) {
92 service_info_ptr->ai_family, service_info_ptr->ai_socktype,
93 service_info_ptr->ai_protocol, child_processes_inherit,
error);
94 if (
error.Success()) {
96 socket->m_sockaddr = service_info_ptr;
102 ::freeaddrinfo(service_info_list);
105 return error.ToError();
111 const bool bind_addr_success = (host_port->hostname ==
"127.0.0.1" || host_port->hostname ==
"localhost")
115 if (!bind_addr_success) {
116 error.SetErrorString(
"Failed to get hostspec to bind for");
117 return error.ToError();
122 err = ::bind(socket->GetNativeSocket(), bind_addr, bind_addr.
GetLength());
124 struct sockaddr_in source_info;
125 socklen_t address_len =
sizeof (
struct sockaddr_in);
126 err = ::getsockname(socket->GetNativeSocket(),
127 (
struct sockaddr *)&source_info, &address_len);
129 return std::move(socket);
134 return std::string(llvm::formatv(
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static const char * g_not_supported_error
bool SetToLocalhost(sa_family_t family, uint16_t port)
bool SetToAnyAddress(sa_family_t family, uint16_t port)
socklen_t GetLength() const
std::string GetIPAddress() const
bool SetPort(uint16_t port)
static const NativeSocket kInvalidSocketValue
static NativeSocket CreateSocket(const int domain, const int type, const int protocol, bool child_processes_inherit, Status &error)
static llvm::Expected< HostAndPort > DecodeHostAndPort(llvm::StringRef host_and_port)
Status Listen(llvm::StringRef name, int backlog) override
std::string GetRemoteConnectionURI() const override
static llvm::Expected< std::unique_ptr< UDPSocket > > Connect(llvm::StringRef name, bool child_processes_inherit)
size_t Send(const void *buf, const size_t num_bytes) override
UDPSocket(bool should_close, bool child_processes_inherit)
Status Accept(Socket *&socket) override
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.