forwarder.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_FORWARDER_H_
  5. #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
  6. #include <sys/select.h>
  7. #include <memory>
  8. #include "base/threading/thread_checker.h"
  9. namespace forwarder2 {
  10. class Socket;
  11. // Internal class that forwards traffic between |socket1| and |socket2|. Note
  12. // that this class is not thread-safe.
  13. class Forwarder {
  14. public:
  15. Forwarder(std::unique_ptr<Socket> socket1, std::unique_ptr<Socket> socket2);
  16. ~Forwarder();
  17. void RegisterFDs(fd_set* read_fds, fd_set* write_fds, int* max_fd);
  18. void ProcessEvents(const fd_set& read_fds, const fd_set& write_fds);
  19. bool IsClosed() const;
  20. void Shutdown();
  21. private:
  22. class BufferedCopier;
  23. base::ThreadChecker thread_checker_;
  24. const std::unique_ptr<Socket> socket1_;
  25. const std::unique_ptr<Socket> socket2_;
  26. // Copies data from socket1 to socket2.
  27. const std::unique_ptr<BufferedCopier> buffer1_;
  28. // Copies data from socket2 to socket1.
  29. const std::unique_ptr<BufferedCopier> buffer2_;
  30. };
  31. } // namespace forwarder2
  32. #endif // TOOLS_ANDROID_FORWARDER2_FORWARDER_H_