LLDB mainline
PipePosix.h
Go to the documentation of this file.
1//===-- PipePosix.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_PIPEPOSIX_H
10#define LLDB_HOST_POSIX_PIPEPOSIX_H
11#include "lldb/Host/PipeBase.h"
12#include <mutex>
13
14namespace lldb_private {
15
16/// \class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h"
17/// A posix-based implementation of Pipe, a class that abtracts
18/// unix style pipes.
19///
20/// A class that abstracts the LLDB core from host pipe functionality.
21class PipePosix : public PipeBase {
22public:
24
25 PipePosix();
27 PipePosix(const PipePosix &) = delete;
28 PipePosix(PipePosix &&pipe_posix);
29 PipePosix &operator=(const PipePosix &) = delete;
30 PipePosix &operator=(PipePosix &&pipe_posix);
31
32 ~PipePosix() override;
33
34 Status CreateNew(bool child_process_inherit) override;
35 Status CreateNew(llvm::StringRef name, bool child_process_inherit) override;
36 Status CreateWithUniqueName(llvm::StringRef prefix,
37 bool child_process_inherit,
38 llvm::SmallVectorImpl<char> &name) override;
39 Status OpenAsReader(llvm::StringRef name,
40 bool child_process_inherit) override;
41 Status
42 OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit,
43 const std::chrono::microseconds &timeout) override;
44
45 bool CanRead() const override;
46 bool CanWrite() const override;
47
48 lldb::pipe_t GetReadPipe() const override {
50 }
51 lldb::pipe_t GetWritePipe() const override {
53 }
54
55 int GetReadFileDescriptor() const override;
56 int GetWriteFileDescriptor() const override;
57 int ReleaseReadFileDescriptor() override;
58 int ReleaseWriteFileDescriptor() override;
59 void CloseReadFileDescriptor() override;
60 void CloseWriteFileDescriptor() override;
61
62 // Close both descriptors
63 void Close() override;
64
65 Status Delete(llvm::StringRef name) override;
66
67 Status WriteWithTimeout(const void *buf, size_t size,
68 const std::chrono::microseconds &timeout,
69 size_t &bytes_written) override;
70 Status ReadWithTimeout(void *buf, size_t size,
71 const std::chrono::microseconds &timeout,
72 size_t &bytes_read) override;
73
74private:
75 bool CanReadUnlocked() const;
76 bool CanWriteUnlocked() const;
77
84 void CloseUnlocked();
85
86 int m_fds[2];
87
88 /// Mutexes for m_fds;
89 mutable std::mutex m_read_mutex;
90 mutable std::mutex m_write_mutex;
91};
92
93} // namespace lldb_private
94
95#endif // LLDB_HOST_POSIX_PIPEPOSIX_H
A posix-based implementation of Pipe, a class that abtracts unix style pipes.
Definition: PipePosix.h:21
Status OpenAsReader(llvm::StringRef name, bool child_process_inherit) override
Definition: PipePosix.cpp:146
int ReleaseWriteFileDescriptorUnlocked()
Definition: PipePosix.cpp:242
int GetReadFileDescriptor() const override
Definition: PipePosix.cpp:208
Status OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit, const std::chrono::microseconds &timeout) override
Definition: PipePosix.cpp:168
lldb::pipe_t GetWritePipe() const override
Definition: PipePosix.h:51
void CloseWriteFileDescriptor() override
Definition: PipePosix.cpp:291
bool CanWrite() const override
Definition: PipePosix.cpp:271
bool CanRead() const override
Definition: PipePosix.cpp:262
void Close() override
Definition: PipePosix.cpp:248
static int kInvalidDescriptor
Definition: PipePosix.h:23
Status ReadWithTimeout(void *buf, size_t size, const std::chrono::microseconds &timeout, size_t &bytes_read) override
Definition: PipePosix.cpp:303
std::mutex m_read_mutex
Mutexes for m_fds;.
Definition: PipePosix.h:89
int ReleaseReadFileDescriptor() override
Definition: PipePosix.cpp:226
Status Delete(llvm::StringRef name) override
Definition: PipePosix.cpp:258
int ReleaseReadFileDescriptorUnlocked()
Definition: PipePosix.cpp:231
void CloseWriteFileDescriptorUnlocked()
Definition: PipePosix.cpp:296
int GetReadFileDescriptorUnlocked() const
Definition: PipePosix.cpp:213
Status CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl< char > &name) override
Definition: PipePosix.cpp:121
bool CanWriteUnlocked() const
Definition: PipePosix.cpp:276
PipePosix & operator=(const PipePosix &)=delete
PipePosix(const PipePosix &)=delete
int ReleaseWriteFileDescriptor() override
Definition: PipePosix.cpp:237
void CloseReadFileDescriptorUnlocked()
Definition: PipePosix.cpp:284
Status WriteWithTimeout(const void *buf, size_t size, const std::chrono::microseconds &timeout, size_t &bytes_written) override
Definition: PipePosix.cpp:338
void CloseReadFileDescriptor() override
Definition: PipePosix.cpp:280
Status CreateNew(bool child_process_inherit) override
Definition: PipePosix.cpp:80
bool CanReadUnlocked() const
Definition: PipePosix.cpp:267
int GetWriteFileDescriptor() const override
Definition: PipePosix.cpp:217
int GetWriteFileDescriptorUnlocked() const
Definition: PipePosix.cpp:222
lldb::pipe_t GetReadPipe() const override
Definition: PipePosix.h:48
std::mutex m_write_mutex
Definition: PipePosix.h:90
An error handling class.
Definition: Status.h:115
A class that represents a running process on the host machine.
int pipe_t
Definition: lldb-types.h:64