PipePosix.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-- PipePosix.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. #ifndef LLDB_HOST_POSIX_PIPEPOSIX_H
  9. #define LLDB_HOST_POSIX_PIPEPOSIX_H
  10. #if defined(__cplusplus)
  11. #include "lldb/Host/PipeBase.h"
  12. namespace lldb_private {
  13. /// \class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h"
  14. /// A posix-based implementation of Pipe, a class that abtracts
  15. /// unix style pipes.
  16. ///
  17. /// A class that abstracts the LLDB core from host pipe functionality.
  18. class PipePosix : public PipeBase {
  19. public:
  20. static int kInvalidDescriptor;
  21. PipePosix();
  22. PipePosix(lldb::pipe_t read, lldb::pipe_t write);
  23. PipePosix(const PipePosix &) = delete;
  24. PipePosix(PipePosix &&pipe_posix);
  25. PipePosix &operator=(const PipePosix &) = delete;
  26. PipePosix &operator=(PipePosix &&pipe_posix);
  27. ~PipePosix() override;
  28. Status CreateNew(bool child_process_inherit) override;
  29. Status CreateNew(llvm::StringRef name, bool child_process_inherit) override;
  30. Status CreateWithUniqueName(llvm::StringRef prefix,
  31. bool child_process_inherit,
  32. llvm::SmallVectorImpl<char> &name) override;
  33. Status OpenAsReader(llvm::StringRef name,
  34. bool child_process_inherit) override;
  35. Status
  36. OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit,
  37. const std::chrono::microseconds &timeout) override;
  38. bool CanRead() const override;
  39. bool CanWrite() const override;
  40. lldb::pipe_t GetReadPipe() const override {
  41. return lldb::pipe_t(GetReadFileDescriptor());
  42. }
  43. lldb::pipe_t GetWritePipe() const override {
  44. return lldb::pipe_t(GetWriteFileDescriptor());
  45. }
  46. int GetReadFileDescriptor() const override;
  47. int GetWriteFileDescriptor() const override;
  48. int ReleaseReadFileDescriptor() override;
  49. int ReleaseWriteFileDescriptor() override;
  50. void CloseReadFileDescriptor() override;
  51. void CloseWriteFileDescriptor() override;
  52. // Close both descriptors
  53. void Close() override;
  54. Status Delete(llvm::StringRef name) override;
  55. Status Write(const void *buf, size_t size, size_t &bytes_written) override;
  56. Status ReadWithTimeout(void *buf, size_t size,
  57. const std::chrono::microseconds &timeout,
  58. size_t &bytes_read) override;
  59. private:
  60. int m_fds[2];
  61. };
  62. } // namespace lldb_private
  63. #endif // #if defined(__cplusplus)
  64. #endif // LLDB_HOST_POSIX_PIPEPOSIX_H