]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Host / posix / ConnectionFileDescriptorPosix.h
1 //===-- ConnectionFileDescriptorPosix.h -------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
11 #define liblldb_Host_posix_ConnectionFileDescriptorPosix_h_
12
13 // C++ Includes
14 #include <atomic>
15 #include <memory>
16 #include <mutex>
17
18 #include "lldb/lldb-forward.h"
19
20 // Other libraries and framework includes
21 // Project 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"
26
27 namespace lldb_private {
28
29 class Error;
30 class Socket;
31 class SocketAddress;
32
33 class ConnectionFileDescriptor : public Connection {
34 public:
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;
45
46   ConnectionFileDescriptor(bool child_processes_inherit = false);
47
48   ConnectionFileDescriptor(int fd, bool owns_fd);
49
50   ConnectionFileDescriptor(Socket *socket);
51
52   ~ConnectionFileDescriptor() override;
53
54   bool IsConnected() const override;
55
56   lldb::ConnectionStatus Connect(llvm::StringRef s, Error *error_ptr) override;
57
58   lldb::ConnectionStatus Disconnect(Error *error_ptr) override;
59
60   size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
61               lldb::ConnectionStatus &status, Error *error_ptr) override;
62
63   size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
64                Error *error_ptr) override;
65
66   std::string GetURI() override;
67
68   lldb::ConnectionStatus BytesAvailable(const Timeout<std::micro> &timeout,
69                                         Error *error_ptr);
70
71   bool InterruptRead() override;
72
73   lldb::IOObjectSP GetReadObject() override { return m_read_sp; }
74
75   uint16_t GetListeningPort(uint32_t timeout_sec);
76
77   bool GetChildProcessesInherit() const;
78   void SetChildProcessesInherit(bool child_processes_inherit);
79
80 protected:
81   void OpenCommandPipe();
82
83   void CloseCommandPipe();
84
85   lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port,
86                                                Error *error_ptr);
87
88   lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
89                                     Error *error_ptr);
90
91   lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Error *error_ptr);
92
93   lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name,
94                                             Error *error_ptr);
95
96   lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name,
97                                            Error *error_ptr);
98
99   lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name,
100                                                    Error *error_ptr);
101
102   lldb::IOObjectSP m_read_sp;
103   lldb::IOObjectSP m_write_sp;
104
105   Predicate<uint16_t>
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
108                         // the port number.
109
110   Pipe m_pipe;
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;
117
118   std::string m_uri;
119
120 private:
121   void InitializeSocket(Socket *socket);
122
123   DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor);
124 };
125
126 } // namespace lldb_private
127
128 #endif // liblldb_ConnectionFileDescriptor_h_