pipe_notifier.h 991 B

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. #include "base/macros.h"
  7. namespace forwarder2 {
  8. // Helper class used to create a unix pipe that sends notifications to the
  9. // |receiver_fd_| file descriptor when called |Notify()|. This should be used
  10. // by the main thread to notify other threads that it must exit.
  11. // The |receiver_fd_| can be put into a fd_set and used in a select together
  12. // with a socket waiting to accept or read.
  13. class PipeNotifier {
  14. public:
  15. PipeNotifier();
  16. ~PipeNotifier();
  17. bool Notify();
  18. int receiver_fd() const { return receiver_fd_; }
  19. void Reset();
  20. private:
  21. int sender_fd_;
  22. int receiver_fd_;
  23. DISALLOW_COPY_AND_ASSIGN(PipeNotifier);
  24. };
  25. } // namespace forwarder
  26. #endif // TOOLS_ANDROID_FORWARDER2_PIPE_NOTIFIER_H_