xref: /llvm-project/lldb/include/lldb/Host/windows/PipeWindows.h (revision ddb9869dd2b5c54fc2369287299e11b9a618d71a)
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 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 { return lldb::pipe_t(m_read); }
49   lldb::pipe_t GetWritePipe() const override { return lldb::pipe_t(m_write); }
50 
51   int GetReadFileDescriptor() const override;
52   int GetWriteFileDescriptor() const override;
53   int ReleaseReadFileDescriptor() override;
54   int ReleaseWriteFileDescriptor() override;
55   void CloseReadFileDescriptor() override;
56   void CloseWriteFileDescriptor() override;
57 
58   void Close() override;
59 
60   Status Delete(llvm::StringRef name) override;
61 
62   Status WriteWithTimeout(const void *buf, size_t size,
63                           const std::chrono::microseconds &timeout,
64                           size_t &bytes_written) override;
65   Status ReadWithTimeout(void *buf, size_t size,
66                          const std::chrono::microseconds &timeout,
67                          size_t &bytes_read) override;
68 
69   // PipeWindows specific methods.  These allow access to the underlying OS
70   // handle.
71   HANDLE GetReadNativeHandle();
72   HANDLE GetWriteNativeHandle();
73 
74 private:
75   Status OpenNamedPipe(llvm::StringRef name, bool child_process_inherit,
76                        bool is_read);
77 
78   HANDLE m_read;
79   HANDLE m_write;
80 
81   int m_read_fd;
82   int m_write_fd;
83 
84   OVERLAPPED m_read_overlapped;
85   OVERLAPPED m_write_overlapped;
86 };
87 
88 } // namespace lldb_private
89 
90 #endif // liblldb_Host_posix_PipePosix_h_
91