OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/android/forwarder2/forwarder.h" | 5 #include "tools/android/forwarder2/forwarder.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
10 #include "tools/android/forwarder2/socket.h" | 10 #include "tools/android/forwarder2/socket.h" |
11 | 11 |
12 namespace forwarder2 { | 12 namespace forwarder2 { |
13 namespace { | 13 namespace { |
14 | 14 |
15 const int kBufferSize = 32 * 1024; | 15 const int kBufferSize = 32 * 1024; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 | 19 |
20 // Helper class to buffer reads and writes from one socket to another. | 20 // Helper class to buffer reads and writes from one socket to another. |
21 // Each implements a small buffer connected two one input socket, and | 21 // Each implements a small buffer connected two one input socket, and |
22 // one output socket. | 22 // one output socket. |
23 // | 23 // |
24 // socket_from_ ---> [BufferedCopier] ---> socket_to_ | 24 // socket_from_ ---> [BufferedCopier] ---> socket_to_ |
25 // | 25 // |
26 // These objects are used in a pair to handle duplex traffic, as in: | 26 // These objects are used in a pair to handle duplex traffic, as in: |
27 // | 27 // |
28 // ------> [BufferedCopier_1] ---> | 28 // -------> [BufferedCopier_1] ---> |
29 // / \ | 29 // | | |
30 // socket_1 * * socket_2 | 30 // socket_1 * * socket_2 |
31 // \ / | 31 // | | |
32 // <------ [BufferedCopier_2] <---- | 32 // <------ [BufferedCopier_2] <---- |
33 // | 33 // |
34 // When a BufferedCopier is in the READING state (see below), it only listens | 34 // When a BufferedCopier is in the READING state (see below), it only listens |
35 // to events on its input socket, and won't detect when its output socket | 35 // to events on its input socket, and won't detect when its output socket |
36 // disconnects. To work around this, its peer will call its Close() method | 36 // disconnects. To work around this, its peer will call its Close() method |
37 // when that happens. | 37 // when that happens. |
38 | 38 |
39 class Forwarder::BufferedCopier { | 39 class Forwarder::BufferedCopier { |
40 public: | 40 public: |
41 // Possible states: | 41 // Possible states: |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return buffer1_->is_closed() && buffer2_->is_closed(); | 246 return buffer1_->is_closed() && buffer2_->is_closed(); |
247 } | 247 } |
248 | 248 |
249 void Forwarder::Shutdown() { | 249 void Forwarder::Shutdown() { |
250 DCHECK(thread_checker_.CalledOnValidThread()); | 250 DCHECK(thread_checker_.CalledOnValidThread()); |
251 buffer1_->Close(); | 251 buffer1_->Close(); |
252 buffer2_->Close(); | 252 buffer2_->Close(); |
253 } | 253 } |
254 | 254 |
255 } // namespace forwarder2 | 255 } // namespace forwarder2 |
OLD | NEW |