pipe_notifier.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_ANDROID_FORWARDER2_PIPE_NOTIFIER_H_
  5. #define TOOLS_ANDROID_FORWARDER2_PIPE_NOTIFIER_H_
  6. namespace forwarder2 {
  7. // Helper class used to create a unix pipe that sends notifications to the
  8. // |receiver_fd_| file descriptor when called |Notify()|. This should be used
  9. // by the main thread to notify other threads that it must exit.
  10. // The |receiver_fd_| can be put into a fd_set and used in a select together
  11. // with a socket waiting to accept or read.
  12. class PipeNotifier {
  13. public:
  14. PipeNotifier();
  15. PipeNotifier(const PipeNotifier&) = delete;
  16. PipeNotifier& operator=(const PipeNotifier&) = delete;
  17. ~PipeNotifier();
  18. bool Notify();
  19. int receiver_fd() const { return receiver_fd_; }
  20. void Reset();
  21. private:
  22. int sender_fd_;
  23. int receiver_fd_;
  24. };
  25. } // namespace forwarder
  26. #endif // TOOLS_ANDROID_FORWARDER2_PIPE_NOTIFIER_H_