Pipe.h 871 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLToolKit(https://github.com/ZLMediaKit/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 Pipe_h
  11. #define Pipe_h
  12. #include <functional>
  13. #include "PipeWrap.h"
  14. #include "EventPoller.h"
  15. namespace toolkit {
  16. class Pipe {
  17. public:
  18. using onRead = std::function<void(int size, const char *buf)>;
  19. Pipe(const onRead &cb = nullptr, const EventPoller::Ptr &poller = nullptr);
  20. ~Pipe();
  21. void send(const char *send, int size = 0);
  22. private:
  23. std::shared_ptr<PipeWrap> _pipe;
  24. EventPoller::Ptr _poller;
  25. };
  26. } // namespace toolkit
  27. #endif /* Pipe_h */