PipeWrap.h 887 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLToolKit(https://github.com/xia-chu/ZLToolKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef PipeWarp_h
  11. #define PipeWarp_h
  12. namespace toolkit {
  13. class PipeWrap {
  14. public:
  15. PipeWrap();
  16. ~PipeWrap();
  17. int write(const void *buf, int n);
  18. int read(void *buf, int n);
  19. int readFD() const {
  20. return _pipe_fd[0];
  21. }
  22. int writeFD() const {
  23. return _pipe_fd[1];
  24. }
  25. private:
  26. int _pipe_fd[2] = { -1,-1 };
  27. void clearFD();
  28. #if defined(_WIN32)
  29. int _listenerFd = -1;
  30. #endif // defined(_WIN32)
  31. };
  32. } /* namespace toolkit */
  33. #endif // !PipeWarp_h