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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 switch (state_) { | 89 switch (state_) { |
90 case STATE_READING: | 90 case STATE_READING: |
91 state_ = STATE_CLOSED; // T03 | 91 state_ = STATE_CLOSED; // T03 |
92 break; | 92 break; |
93 case STATE_WRITING: | 93 case STATE_WRITING: |
94 state_ = STATE_CLOSING; // T07 | 94 state_ = STATE_CLOSING; // T07 |
95 break; | 95 break; |
96 case STATE_CLOSING: | 96 case STATE_CLOSING: |
97 break; // T10 | 97 break; // T10 |
98 case STATE_CLOSED: | 98 case STATE_CLOSED: |
99 ; | 99 break; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 // Call this before select(). This updates |read_fds|, | 103 // Call this before select(). This updates |read_fds|, |
104 // |write_fds| and |max_fd| appropriately *if* the buffer isn't closed. | 104 // |write_fds| and |max_fd| appropriately *if* the buffer isn't closed. |
105 void PrepareSelect(fd_set* read_fds, fd_set* write_fds, int* max_fd) { | 105 void PrepareSelect(fd_set* read_fds, fd_set* write_fds, int* max_fd) { |
106 int fd; | 106 int fd; |
107 switch (state_) { | 107 switch (state_) { |
108 case STATE_READING: | 108 case STATE_READING: |
109 DCHECK(bytes_read_ == 0); | 109 DCHECK(bytes_read_ == 0); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 write_offset_ = 0; | 187 write_offset_ = 0; |
188 bytes_read_ = 0; | 188 bytes_read_ = 0; |
189 if (state_ == STATE_CLOSING) { | 189 if (state_ == STATE_CLOSING) { |
190 ForceClose(); // T09 | 190 ForceClose(); // T09 |
191 return; | 191 return; |
192 } | 192 } |
193 state_ = STATE_READING; // T05 | 193 state_ = STATE_READING; // T05 |
194 break; | 194 break; |
195 | 195 |
196 case STATE_CLOSED: | 196 case STATE_CLOSED: |
197 ; | 197 break; |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 private: | 201 private: |
202 // Internal method used to close the buffer and notify the peer, if any. | 202 // Internal method used to close the buffer and notify the peer, if any. |
203 void ForceClose() { | 203 void ForceClose() { |
204 if (peer_) { | 204 if (peer_) { |
205 peer_->Close(); | 205 peer_->Close(); |
206 peer_ = NULL; | 206 peer_ = NULL; |
207 } | 207 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return buffer1_->is_closed() && buffer2_->is_closed(); | 252 return buffer1_->is_closed() && buffer2_->is_closed(); |
253 } | 253 } |
254 | 254 |
255 void Forwarder::Shutdown() { | 255 void Forwarder::Shutdown() { |
256 DCHECK(thread_checker_.CalledOnValidThread()); | 256 DCHECK(thread_checker_.CalledOnValidThread()); |
257 buffer1_->Close(); | 257 buffer1_->Close(); |
258 buffer2_->Close(); | 258 buffer2_->Close(); |
259 } | 259 } |
260 | 260 |
261 } // namespace forwarder2 | 261 } // namespace forwarder2 |
OLD | NEW |