Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tools/android/forwarder2/forwarder.cc

Issue 697393002: Fix device_forwarder build with FORTIFY_SOURCE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 break; 129 break;
130 130
131 case STATE_CLOSED: 131 case STATE_CLOSED:
132 return; 132 return;
133 } 133 }
134 *max_fd = std::max(*max_fd, fd); 134 *max_fd = std::max(*max_fd, fd);
135 } 135 }
136 136
137 // Call this after a select() call to operate over the buffer. 137 // Call this after a select() call to operate over the buffer.
138 void ProcessSelect(const fd_set& read_fds, const fd_set& write_fds) { 138 void ProcessSelect(const fd_set& read_fds, const fd_set& write_fds) {
139 int fd, ret; 139 int fd;
140 int ret;
141 // With FORTIFY_SOURCE, FD_ISSET is implemented as a function that takes a
142 // non-const fd_set*. Make a copy of the passed arguments so we can safely
143 // take a reference.
144 fd_set read_fds_copy = read_fds;
145 fd_set write_fds_copy = write_fds;
140 switch (state_) { 146 switch (state_) {
141 case STATE_READING: 147 case STATE_READING:
142 fd = socket_from_->fd(); 148 fd = socket_from_->fd();
143 if (fd < 0) { 149 if (fd < 0) {
144 state_ = STATE_CLOSED; // T02 150 state_ = STATE_CLOSED; // T02
145 return; 151 return;
146 } 152 }
147 if (!FD_ISSET(fd, &read_fds)) 153 if (!FD_ISSET(fd, &read_fds_copy))
148 return; 154 return;
149 155
150 ret = socket_from_->NonBlockingRead(buffer_, kBufferSize); 156 ret = socket_from_->NonBlockingRead(buffer_, kBufferSize);
151 if (ret <= 0) { 157 if (ret <= 0) {
152 ForceClose(); // T02 158 ForceClose(); // T02
153 return; 159 return;
154 } 160 }
155 bytes_read_ = ret; 161 bytes_read_ = ret;
156 write_offset_ = 0; 162 write_offset_ = 0;
157 state_ = STATE_WRITING; // T01 163 state_ = STATE_WRITING; // T01
158 break; 164 break;
159 165
160 case STATE_WRITING: 166 case STATE_WRITING:
161 case STATE_CLOSING: 167 case STATE_CLOSING:
162 fd = socket_to_->fd(); 168 fd = socket_to_->fd();
163 if (fd < 0) { 169 if (fd < 0) {
164 ForceClose(); // T06 + T11 170 ForceClose(); // T06 + T11
165 return; 171 return;
166 } 172 }
167 if (!FD_ISSET(fd, &write_fds)) 173 if (!FD_ISSET(fd, &write_fds_copy))
168 return; 174 return;
169 175
170 ret = socket_to_->NonBlockingWrite(buffer_ + write_offset_, 176 ret = socket_to_->NonBlockingWrite(buffer_ + write_offset_,
171 bytes_read_ - write_offset_); 177 bytes_read_ - write_offset_);
172 if (ret <= 0) { 178 if (ret <= 0) {
173 ForceClose(); // T06 + T11 179 ForceClose(); // T06 + T11
174 return; 180 return;
175 } 181 }
176 182
177 write_offset_ += ret; 183 write_offset_ += ret;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return buffer1_->is_closed() && buffer2_->is_closed(); 252 return buffer1_->is_closed() && buffer2_->is_closed();
247 } 253 }
248 254
249 void Forwarder::Shutdown() { 255 void Forwarder::Shutdown() {
250 DCHECK(thread_checker_.CalledOnValidThread()); 256 DCHECK(thread_checker_.CalledOnValidThread());
251 buffer1_->Close(); 257 buffer1_->Close();
252 buffer2_->Close(); 258 buffer2_->Close();
253 } 259 }
254 260
255 } // namespace forwarder2 261 } // namespace forwarder2
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698