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
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
68protected:
69 void OpenCommandPipe();
70
71 void CloseCommandPipe();
72
75 llvm::StringRef socket_name,
76 llvm::function_ref<void(Socket &)> post_listen_callback,
77 Status *error_ptr);
78
80 llvm::StringRef socket_name,
81 Status *error_ptr);
82
83 lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port,
84 socket_id_callback_type socket_id_callback,
85 Status *error_ptr);
86
87 lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
88 socket_id_callback_type socket_id_callback,
89 Status *error_ptr);
90
91 lldb::ConnectionStatus ConnectUDP(llvm::StringRef args,
92 socket_id_callback_type socket_id_callback,
93 Status *error_ptr);
94
96 ConnectNamedSocket(llvm::StringRef socket_name,
97 socket_id_callback_type socket_id_callback,
98 Status *error_ptr);
99
101 AcceptNamedSocket(llvm::StringRef socket_name,
102 socket_id_callback_type socket_id_callback,
103 Status *error_ptr);
104
106 AcceptAbstractSocket(llvm::StringRef socket_name,
107 socket_id_callback_type socket_id_callback,
108 Status *error_ptr);
109
111 ConnectAbstractSocket(llvm::StringRef socket_name,
112 socket_id_callback_type socket_id_callback,
113 Status *error_ptr);
114
115 lldb::ConnectionStatus ConnectFD(llvm::StringRef args,
116 socket_id_callback_type socket_id_callback,
117 Status *error_ptr);
118
119 lldb::ConnectionStatus ConnectFile(llvm::StringRef args,
120 socket_id_callback_type socket_id_callback,
121 Status *error_ptr);
122
124 ConnectSerialPort(llvm::StringRef args,
125 socket_id_callback_type socket_id_callback,
126 Status *error_ptr);
127
129
131 std::recursive_mutex m_mutex;
132 std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
133 // if we get woken up from
134 // BytesAvailable to disconnect, we won't try to read again.
135
136 std::string m_uri;
137
138private:
139 void InitializeSocket(Socket *socket);
140
144};
145
146} // namespace lldb_private
147
148#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)
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:115
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::IOObject > IOObjectSP
Definition: lldb-forward.h:362
ConnectionStatus
Connection Status Types.