1 //===-- ConnectionFileDescriptorPosix.h -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
11 #define liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
18 #include "lldb/lldb-forward.h"
20 // Other libraries and framework includes
22 #include "lldb/Core/Connection.h"
23 #include "lldb/Host/IOObject.h"
24 #include "lldb/Host/Pipe.h"
25 #include "lldb/Host/Predicate.h"
27 namespace lldb_private {
33 class ConnectionFileDescriptor : public Connection {
35 static const char *LISTEN_SCHEME;
36 static const char *ACCEPT_SCHEME;
37 static const char *UNIX_ACCEPT_SCHEME;
38 static const char *CONNECT_SCHEME;
39 static const char *TCP_CONNECT_SCHEME;
40 static const char *UDP_SCHEME;
41 static const char *UNIX_CONNECT_SCHEME;
42 static const char *UNIX_ABSTRACT_CONNECT_SCHEME;
43 static const char *FD_SCHEME;
44 static const char *FILE_SCHEME;
46 ConnectionFileDescriptor(bool child_processes_inherit = false);
48 ConnectionFileDescriptor(int fd, bool owns_fd);
50 ConnectionFileDescriptor(Socket *socket);
52 ~ConnectionFileDescriptor() override;
54 bool IsConnected() const override;
56 lldb::ConnectionStatus Connect(llvm::StringRef s, Error *error_ptr) override;
58 lldb::ConnectionStatus Disconnect(Error *error_ptr) override;
60 size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
61 lldb::ConnectionStatus &status, Error *error_ptr) override;
63 size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
64 Error *error_ptr) override;
66 std::string GetURI() override;
68 lldb::ConnectionStatus BytesAvailable(const Timeout<std::micro> &timeout,
71 bool InterruptRead() override;
73 lldb::IOObjectSP GetReadObject() override { return m_read_sp; }
75 uint16_t GetListeningPort(uint32_t timeout_sec);
77 bool GetChildProcessesInherit() const;
78 void SetChildProcessesInherit(bool child_processes_inherit);
81 void OpenCommandPipe();
83 void CloseCommandPipe();
85 lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port,
88 lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
91 lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Error *error_ptr);
93 lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name,
96 lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name,
99 lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name,
102 lldb::IOObjectSP m_read_sp;
103 lldb::IOObjectSP m_write_sp;
106 m_port_predicate; // Used when binding to port zero to wait for the thread
107 // that creates the socket, binds and listens to resolve
111 std::recursive_mutex m_mutex;
112 std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
113 // if we get woken up from
114 // BytesAvailable to disconnect, we won't try to read again.
115 bool m_waiting_for_accept;
116 bool m_child_processes_inherit;
121 void InitializeSocket(Socket *socket);
123 DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor);
126 } // namespace lldb_private
128 #endif // liblldb_ConnectionFileDescriptor_h_