1 //===-- PipeWindows.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 liblldb_Host_windows_PipeWindows_h_ 10 #define liblldb_Host_windows_PipeWindows_h_ 11 12 #include "lldb/Host/PipeBase.h" 13 #include "lldb/Host/windows/windows.h" 14 15 namespace lldb_private { 16 17 /// \class Pipe PipeWindows.h "lldb/Host/windows/PipeWindows.h" 18 /// A windows-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. 22 class PipeWindows : public PipeBase { 23 public: 24 static const int kInvalidDescriptor = -1; 25 26 public: 27 PipeWindows(); 28 PipeWindows(lldb::pipe_t read, lldb::pipe_t write); 29 ~PipeWindows() override; 30 31 // Create an unnamed pipe. 32 Status CreateNew(bool child_process_inherit) override; 33 34 // Create a named pipe. 35 Status CreateNewNamed(bool child_process_inherit); 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 GetReadPipe()49 lldb::pipe_t GetReadPipe() const override { return lldb::pipe_t(m_read); } GetWritePipe()50 lldb::pipe_t GetWritePipe() const override { return lldb::pipe_t(m_write); } 51 52 int GetReadFileDescriptor() const override; 53 int GetWriteFileDescriptor() const override; 54 int ReleaseReadFileDescriptor() override; 55 int ReleaseWriteFileDescriptor() override; 56 void CloseReadFileDescriptor() override; 57 void CloseWriteFileDescriptor() override; 58 59 void Close() override; 60 61 Status Delete(llvm::StringRef name) override; 62 63 Status Write(const void *buf, size_t size, size_t &bytes_written) override; 64 Status ReadWithTimeout(void *buf, size_t size, 65 const std::chrono::microseconds &timeout, 66 size_t &bytes_read) override; 67 68 // PipeWindows specific methods. These allow access to the underlying OS 69 // handle. 70 HANDLE GetReadNativeHandle(); 71 HANDLE GetWriteNativeHandle(); 72 73 private: 74 Status OpenNamedPipe(llvm::StringRef name, bool child_process_inherit, 75 bool is_read); 76 77 HANDLE m_read; 78 HANDLE m_write; 79 80 int m_read_fd; 81 int m_write_fd; 82 83 OVERLAPPED m_read_overlapped; 84 OVERLAPPED m_write_overlapped; 85 }; 86 87 } // namespace lldb_private 88 89 #endif // liblldb_Host_posix_PipePosix_h_ 90