Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / android / forwarder2 / forwarder.h
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
5 #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
6 #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
7
8 #include <sys/select.h>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread_checker.h"
12
13 namespace forwarder2 {
14
15 class Socket;
16
17 // Internal class that forwards traffic between |socket1| and |socket2|. Note
18 // that this class is not thread-safe.
19 class Forwarder {
20  public:
21   Forwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2);
22
23   ~Forwarder();
24
25   void RegisterFDs(fd_set* read_fds, fd_set* write_fds, int* max_fd);
26
27   void ProcessEvents(const fd_set& read_fds, const fd_set& write_fds);
28
29   bool IsClosed() const;
30
31   void Shutdown();
32
33  private:
34   class BufferedCopier;
35
36   base::ThreadChecker thread_checker_;
37   const scoped_ptr<Socket> socket1_;
38   const scoped_ptr<Socket> socket2_;
39   // Copies data from socket1 to socket2.
40   const scoped_ptr<BufferedCopier> buffer1_;
41   // Copies data from socket2 to socket1.
42   const scoped_ptr<BufferedCopier> buffer2_;
43 };
44
45 }  // namespace forwarder2
46
47 #endif  // TOOLS_ANDROID_FORWARDER2_FORWARDER_H_