Pipe.h 874 B

123456789101112131415161718192021222324252627282930313233343536
  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 Pipe_h
  11. #define Pipe_h
  12. #include <stdio.h>
  13. #include <functional>
  14. #include "PipeWrap.h"
  15. #include "EventPoller.h"
  16. using namespace std;
  17. namespace toolkit {
  18. class Pipe
  19. {
  20. public:
  21. Pipe(const function<void(int size,const char *buf)> &onRead=nullptr, const EventPoller::Ptr &poller = nullptr);
  22. ~Pipe();
  23. void send(const char *send,int size=0);
  24. private:
  25. std::shared_ptr<PipeWrap> _pipe;
  26. EventPoller::Ptr _poller;
  27. };
  28. } // namespace toolkit
  29. #endif /* Pipe_h */