LLDB mainline
common/DomainSocket.h
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
9#ifndef LLDB_HOST_COMMON_DOMAINSOCKET_H
10#define LLDB_HOST_COMMON_DOMAINSOCKET_H
11
12#include "lldb/Host/Socket.h"
13#include <string>
14#include <vector>
15
16namespace lldb_private {
17
18/// Cross-platform AF_UNIX domain-socket logic.
19///
20/// Every operation on a domain socket (connect, listen, accept, name
21/// lookup) is identical on POSIX and Windows, so it all lives here. The only
22/// operation which differs between platforms is the CreatePair() factory: POSIX
23/// has socketpair(2) while Windows must emulate it. That factory therefore
24/// lives in the DomainSocketPosix / DomainSocketWindows implementation classes.
25class DomainSocket : public Socket {
26public:
27 DomainSocket(NativeSocket socket, bool should_close);
28 explicit DomainSocket(bool should_close);
29
30 using Pair =
31 std::pair<std::unique_ptr<DomainSocket>, std::unique_ptr<DomainSocket>>;
32
33 Status Connect(llvm::StringRef name) override;
34 Status Listen(llvm::StringRef name, int backlog) override;
35
36 using Socket::Accept;
37 llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>>
38 Accept(MainLoopBase &loop,
39 std::function<void(std::unique_ptr<Socket> socket)> sock_cb) override;
40
41 std::string GetRemoteConnectionURI() const override;
42
43 std::vector<std::string> GetListeningConnectionURI() const override;
44
45 static llvm::Expected<std::unique_ptr<DomainSocket>>
46 FromBoundNativeSocket(NativeSocket sockfd, bool should_close);
47
48protected:
50 DomainSocket(SocketProtocol protocol, NativeSocket socket, bool should_close);
51
52 virtual size_t GetNameOffset() const;
53 virtual void DeleteSocketFile(llvm::StringRef name);
54 std::string GetSocketName() const;
55
56private:
57 DomainSocket(NativeSocket socket, const DomainSocket &listen_socket);
58};
59} // namespace lldb_private
60
61#endif // LLDB_HOST_COMMON_DOMAINSOCKET_H
DomainSocket(NativeSocket socket, bool should_close)
Status Listen(llvm::StringRef name, int backlog) override
llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept(MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb) override
std::pair< std::unique_ptr< DomainSocket >, std::unique_ptr< DomainSocket > > Pair
virtual size_t GetNameOffset() const
virtual void DeleteSocketFile(llvm::StringRef name)
Status Connect(llvm::StringRef name) override
static llvm::Expected< std::unique_ptr< DomainSocket > > FromBoundNativeSocket(NativeSocket sockfd, bool should_close)
std::string GetSocketName() const
std::string GetRemoteConnectionURI() const override
std::vector< std::string > GetListeningConnectionURI() const override
virtual llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept(MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb)=0
Socket(SocketProtocol protocol, bool should_close)
Definition Socket.cpp:170
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.
int NativeSocket
Definition Socket.h:41