LLDB mainline
ConnectionFileDescriptorPosix.h
Go to the documentation of this file.
1//===-- ConnectionFileDescriptorPosix.h -------------------------*- C++ -*-===//
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_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
10#define LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
11
12#include <atomic>
13#include <memory>
14#include <mutex>
15
16#include "lldb/lldb-forward.h"
17
18#include "lldb/Host/Pipe.h"
19#include "lldb/Host/Socket.h"
22
23namespace lldb_private {
24
25class Status;
26class Socket;
27class SocketAddress;
28
30public:
31 typedef llvm::function_ref<void(llvm::StringRef local_socket_id)>
33
34 ConnectionFileDescriptor(bool child_processes_inherit = false);
35
36 ConnectionFileDescriptor(int fd, bool owns_fd);
37
39
41
42 bool IsConnected() const override;
43
44 lldb::ConnectionStatus Connect(llvm::StringRef url,
45 Status *error_ptr) override;
46
47 lldb::ConnectionStatus Connect(llvm::StringRef url,
48 socket_id_callback_type socket_id_callback,
49 Status *error_ptr);
50
51 lldb::ConnectionStatus Disconnect(Status *error_ptr) override;
52
53 size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
54 lldb::ConnectionStatus &status, Status *error_ptr) override;
55
56 size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
57 Status *error_ptr) override;
58
59 std::string GetURI() override;
60
62 Status *error_ptr);
63
64 bool InterruptRead() override;
65
66 lldb::IOObjectSP GetReadObject() override { return m_io_sp; }
67
68 bool GetChildProcessesInherit() const;
69 void SetChildProcessesInherit(bool child_processes_inherit);
70
71protected:
72 void OpenCommandPipe();
73
74 void CloseCommandPipe();
75
78 llvm::StringRef socket_name,
79 llvm::function_ref<void(Socket &)> post_listen_callback,
80 Status *error_ptr);
81
83 llvm::StringRef socket_name,
84 Status *error_ptr);
85
86 lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port,
87 socket_id_callback_type socket_id_callback,
88 Status *error_ptr);
89
90 lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
91 socket_id_callback_type socket_id_callback,
92 Status *error_ptr);
93
94 lldb::ConnectionStatus ConnectUDP(llvm::StringRef args,
95 socket_id_callback_type socket_id_callback,
96 Status *error_ptr);
97
99 ConnectNamedSocket(llvm::StringRef socket_name,
100 socket_id_callback_type socket_id_callback,
101 Status *error_ptr);
102
104 AcceptNamedSocket(llvm::StringRef socket_name,
105 socket_id_callback_type socket_id_callback,
106 Status *error_ptr);
107
109 AcceptAbstractSocket(llvm::StringRef socket_name,
110 socket_id_callback_type socket_id_callback,
111 Status *error_ptr);
112
114 ConnectAbstractSocket(llvm::StringRef socket_name,
115 socket_id_callback_type socket_id_callback,
116 Status *error_ptr);
117
118 lldb::ConnectionStatus ConnectFD(llvm::StringRef args,
119 socket_id_callback_type socket_id_callback,
120 Status *error_ptr);
121
122 lldb::ConnectionStatus ConnectFile(llvm::StringRef args,
123 socket_id_callback_type socket_id_callback,
124 Status *error_ptr);
125
127 ConnectSerialPort(llvm::StringRef args,
128 socket_id_callback_type socket_id_callback,
129 Status *error_ptr);
130
132
134 std::recursive_mutex m_mutex;
135 std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
136 // if we get woken up from
137 // BytesAvailable to disconnect, we won't try to read again.
139
140 std::string m_uri;
141
142private:
143 void InitializeSocket(Socket *socket);
144
148};
149
150} // namespace lldb_private
151
152#endif // LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
const ConnectionFileDescriptor & operator=(const ConnectionFileDescriptor &)=delete
lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
ConnectionFileDescriptor(const ConnectionFileDescriptor &)=delete
lldb::ConnectionStatus ConnectNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus AcceptAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
void SetChildProcessesInherit(bool child_processes_inherit)
bool InterruptRead() override
Interrupts an ongoing Read() operation.
lldb::ConnectionStatus Connect(llvm::StringRef url, Status *error_ptr) override
Connect using the connect string url.
bool IsConnected() const override
Check if the connection is valid.
lldb::ConnectionStatus AcceptNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
lldb::IOObjectSP GetReadObject() override
Returns the underlying IOObject used by the Connection.
lldb::ConnectionStatus AcceptSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, llvm::function_ref< void(Socket &)> post_listen_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectFD(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
lldb::ConnectionStatus BytesAvailable(const Timeout< std::micro > &timeout, Status *error_ptr)
lldb::ConnectionStatus ConnectFile(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr)
std::string GetURI() override
Returns a URI that describes this connection object.
lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
llvm::function_ref< void(llvm::StringRef local_socket_id)> socket_id_callback_type
A communication connection class.
Definition: Connection.h:41
A posix-based implementation of Pipe, a class that abtracts unix style pipes.
Definition: PipePosix.h:21
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::IOObject > IOObjectSP
Definition: lldb-forward.h:360
ConnectionStatus
Connection Status Types.