1 //===-- PipePosix.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_Host_posix_PipePosix_h_ 11 #define liblldb_Host_posix_PipePosix_h_ 12 #if defined(__cplusplus) 13 14 #include "lldb/Host/PipeBase.h" 15 16 namespace lldb_private { 17 18 //---------------------------------------------------------------------- 19 /// @class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h" 20 /// A posix-based implementation of Pipe, a class that abtracts 21 /// unix style pipes. 22 /// 23 /// A class that abstracts the LLDB core from host pipe functionality. 24 //---------------------------------------------------------------------- 25 class PipePosix : public PipeBase { 26 public: 27 static int kInvalidDescriptor; 28 29 PipePosix(); 30 PipePosix(lldb::pipe_t read, lldb::pipe_t write); 31 PipePosix(const PipePosix &) = delete; 32 PipePosix(PipePosix &&pipe_posix); 33 PipePosix &operator=(const PipePosix &) = delete; 34 PipePosix &operator=(PipePosix &&pipe_posix); 35 36 ~PipePosix() override; 37 38 Status CreateNew(bool child_process_inherit) override; 39 Status CreateNew(llvm::StringRef name, bool child_process_inherit) override; 40 Status CreateWithUniqueName(llvm::StringRef prefix, 41 bool child_process_inherit, 42 llvm::SmallVectorImpl<char> &name) override; 43 Status OpenAsReader(llvm::StringRef name, 44 bool child_process_inherit) override; 45 Status 46 OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit, 47 const std::chrono::microseconds &timeout) override; 48 49 bool CanRead() const override; 50 bool CanWrite() const override; 51 GetReadPipe()52 lldb::pipe_t GetReadPipe() const override { 53 return lldb::pipe_t(GetReadFileDescriptor()); 54 } GetWritePipe()55 lldb::pipe_t GetWritePipe() const override { 56 return lldb::pipe_t(GetWriteFileDescriptor()); 57 } 58 59 int GetReadFileDescriptor() const override; 60 int GetWriteFileDescriptor() const override; 61 int ReleaseReadFileDescriptor() override; 62 int ReleaseWriteFileDescriptor() override; 63 void CloseReadFileDescriptor() override; 64 void CloseWriteFileDescriptor() override; 65 66 // Close both descriptors 67 void Close() override; 68 69 Status Delete(llvm::StringRef name) override; 70 71 Status Write(const void *buf, size_t size, size_t &bytes_written) override; 72 Status ReadWithTimeout(void *buf, size_t size, 73 const std::chrono::microseconds &timeout, 74 size_t &bytes_read) override; 75 76 private: 77 int m_fds[2]; 78 }; 79 80 } // namespace lldb_private 81 82 #endif // #if defined(__cplusplus) 83 #endif // liblldb_Host_posix_PipePosix_h_ 84