1 //===-- ConnectionFileDescriptorPosix.h -------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
10 #define liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
16 #include "lldb/lldb-forward.h"
18 #include "lldb/Host/Pipe.h"
19 #include "lldb/Utility/Connection.h"
20 #include "lldb/Utility/IOObject.h"
21 #include "lldb/Utility/Predicate.h"
23 namespace lldb_private {
29 class ConnectionFileDescriptor : public Connection {
31 static const char *LISTEN_SCHEME;
32 static const char *ACCEPT_SCHEME;
33 static const char *UNIX_ACCEPT_SCHEME;
34 static const char *CONNECT_SCHEME;
35 static const char *TCP_CONNECT_SCHEME;
36 static const char *UDP_SCHEME;
37 static const char *UNIX_CONNECT_SCHEME;
38 static const char *UNIX_ABSTRACT_CONNECT_SCHEME;
39 static const char *FD_SCHEME;
40 static const char *FILE_SCHEME;
42 ConnectionFileDescriptor(bool child_processes_inherit = false);
44 ConnectionFileDescriptor(int fd, bool owns_fd);
46 ConnectionFileDescriptor(Socket *socket);
48 ~ConnectionFileDescriptor() override;
50 bool IsConnected() const override;
52 lldb::ConnectionStatus Connect(llvm::StringRef s, Status *error_ptr) override;
54 lldb::ConnectionStatus Disconnect(Status *error_ptr) override;
56 size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
57 lldb::ConnectionStatus &status, Status *error_ptr) override;
59 size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
60 Status *error_ptr) override;
62 std::string GetURI() override;
64 lldb::ConnectionStatus BytesAvailable(const Timeout<std::micro> &timeout,
67 bool InterruptRead() override;
69 lldb::IOObjectSP GetReadObject() override { return m_read_sp; }
71 uint16_t GetListeningPort(const Timeout<std::micro> &timeout);
73 bool GetChildProcessesInherit() const;
74 void SetChildProcessesInherit(bool child_processes_inherit);
77 void OpenCommandPipe();
79 void CloseCommandPipe();
81 lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port,
84 lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
87 lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Status *error_ptr);
89 lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name,
92 lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name,
95 lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name,
98 lldb::IOObjectSP m_read_sp;
99 lldb::IOObjectSP m_write_sp;
102 m_port_predicate; // Used when binding to port zero to wait for the thread
103 // that creates the socket, binds and listens to
104 // resolve the port number.
107 std::recursive_mutex m_mutex;
108 std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
109 // if we get woken up from
110 // BytesAvailable to disconnect, we won't try to read again.
111 bool m_waiting_for_accept;
112 bool m_child_processes_inherit;
117 void InitializeSocket(Socket *socket);
119 DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor);
122 } // namespace lldb_private
124 #endif // liblldb_ConnectionFileDescriptor_h_