PipePosix.h revision 353358
1217309Snwhitehorn//===-- PipePosix.h ---------------------------------------------*- C++ -*-===// 2217309Snwhitehorn// 3217309Snwhitehorn// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4217309Snwhitehorn// See https://llvm.org/LICENSE.txt for license information. 5217309Snwhitehorn// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6217309Snwhitehorn// 7217309Snwhitehorn//===----------------------------------------------------------------------===// 8217309Snwhitehorn 9217309Snwhitehorn#ifndef liblldb_Host_posix_PipePosix_h_ 10217309Snwhitehorn#define liblldb_Host_posix_PipePosix_h_ 11217309Snwhitehorn#if defined(__cplusplus) 12217309Snwhitehorn 13217309Snwhitehorn#include "lldb/Host/PipeBase.h" 14217309Snwhitehorn 15217309Snwhitehornnamespace lldb_private { 16217309Snwhitehorn 17217309Snwhitehorn/// \class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h" 18217309Snwhitehorn/// A posix-based implementation of Pipe, a class that abtracts 19/// unix style pipes. 20/// 21/// A class that abstracts the LLDB core from host pipe functionality. 22class PipePosix : public PipeBase { 23public: 24 static int kInvalidDescriptor; 25 26 PipePosix(); 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); 32 33 ~PipePosix() override; 34 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; 42 Status 43 OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit, 44 const std::chrono::microseconds &timeout) override; 45 46 bool CanRead() const override; 47 bool CanWrite() const override; 48 49 lldb::pipe_t GetReadPipe() const override { 50 return lldb::pipe_t(GetReadFileDescriptor()); 51 } 52 lldb::pipe_t GetWritePipe() const override { 53 return lldb::pipe_t(GetWriteFileDescriptor()); 54 } 55 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; 62 63 // Close both descriptors 64 void Close() override; 65 66 Status Delete(llvm::StringRef name) override; 67 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; 72 73private: 74 int m_fds[2]; 75}; 76 77} // namespace lldb_private 78 79#endif // #if defined(__cplusplus) 80#endif // liblldb_Host_posix_PipePosix_h_ 81