LLDB mainline
DomainSocketPosix.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11
12#include "llvm/Support/Errno.h"
13#include "llvm/Support/Error.h"
14
15#include <cassert>
16#include <fcntl.h>
17#include <memory>
18#include <sys/socket.h>
19
20using namespace lldb;
21using namespace lldb_private;
22
23llvm::Expected<DomainSocket::Pair> DomainSocketPosix::CreatePair() {
24 int sockets[2];
25 int type = SOCK_STREAM;
26#ifdef SOCK_CLOEXEC
27 type |= SOCK_CLOEXEC;
28#endif
29 if (socketpair(AF_UNIX, type, 0, sockets) == -1)
30 return llvm::errorCodeToError(llvm::errnoAsErrorCode());
31
32#ifndef SOCK_CLOEXEC
33 for (int s : sockets) {
34 int r = fcntl(s, F_SETFD, FD_CLOEXEC | fcntl(s, F_GETFD));
35 assert(r == 0);
36 (void)r;
37 }
38#endif
39
40#if defined(SO_NOSIGPIPE)
41 Log *log = GetLog(LLDBLog::Host);
42 if (Socket::SetOption(sockets[0], SOL_SOCKET, SO_NOSIGPIPE, 1) == -1)
43 LLDB_LOG(log, "failed to set NO_SIGPIPE on fd {0}: {1}", sockets[0],
44 llvm::sys::StrError());
45 if (Socket::SetOption(sockets[1], SOL_SOCKET, SO_NOSIGPIPE, 1) == -1)
46 LLDB_LOG(log, "failed to set NO_SIGPIPE on fd {0}: {1}", sockets[1],
47 llvm::sys::StrError());
48#endif
49
50 return Pair(std::unique_ptr<DomainSocket>(new DomainSocketPosix(
51 ProtocolUnixDomain, sockets[0], /*should_close=*/true)),
52 std::unique_ptr<DomainSocket>(new DomainSocketPosix(
53 ProtocolUnixDomain, sockets[1], /*should_close=*/true)));
54}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:376
"lldb/Host/posix/DomainSocketPosix.h" POSIX implementation of the platform-specific parts of DomainSo...
static llvm::Expected< Pair > CreatePair()
Create a connected pair of domain sockets using socketpair(2).
std::pair< std::unique_ptr< DomainSocket >, std::unique_ptr< DomainSocket > > Pair
static int SetOption(NativeSocket sockfd, int level, int option_name, int option_value)
Definition Socket.cpp:405
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.
Definition Log.h:339