1 //===-- PipePosix.h ---------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Host_posix_PipePosix_h_
10 #define liblldb_Host_posix_PipePosix_h_
11 #if defined(__cplusplus)
13 #include "lldb/Host/PipeBase.h"
15 namespace lldb_private {
17 /// \class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h"
18 /// A posix-based implementation of Pipe, a class that abtracts
21 /// A class that abstracts the LLDB core from host pipe functionality.
22 class PipePosix : public PipeBase {
24 static int kInvalidDescriptor;
27 PipePosix(lldb::pipe_t read, lldb::pipe_t write);
28 PipePosix(const PipePosix &) = delete;
29 PipePosix(PipePosix &&pipe_posix);
30 PipePosix &operator=(const PipePosix &) = delete;
31 PipePosix &operator=(PipePosix &&pipe_posix);
33 ~PipePosix() override;
35 Status CreateNew(bool child_process_inherit) override;
36 Status CreateNew(llvm::StringRef name, bool child_process_inherit) override;
37 Status CreateWithUniqueName(llvm::StringRef prefix,
38 bool child_process_inherit,
39 llvm::SmallVectorImpl<char> &name) override;
40 Status OpenAsReader(llvm::StringRef name,
41 bool child_process_inherit) override;
43 OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit,
44 const std::chrono::microseconds &timeout) override;
46 bool CanRead() const override;
47 bool CanWrite() const override;
49 lldb::pipe_t GetReadPipe() const override {
50 return lldb::pipe_t(GetReadFileDescriptor());
52 lldb::pipe_t GetWritePipe() const override {
53 return lldb::pipe_t(GetWriteFileDescriptor());
56 int GetReadFileDescriptor() const override;
57 int GetWriteFileDescriptor() const override;
58 int ReleaseReadFileDescriptor() override;
59 int ReleaseWriteFileDescriptor() override;
60 void CloseReadFileDescriptor() override;
61 void CloseWriteFileDescriptor() override;
63 // Close both descriptors
64 void Close() override;
66 Status Delete(llvm::StringRef name) override;
68 Status Write(const void *buf, size_t size, size_t &bytes_written) override;
69 Status ReadWithTimeout(void *buf, size_t size,
70 const std::chrono::microseconds &timeout,
71 size_t &bytes_read) override;
77 } // namespace lldb_private
79 #endif // #if defined(__cplusplus)
80 #endif // liblldb_Host_posix_PipePosix_h_