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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_tcp.cc

Issue 691253003: Avoid calling P2PSocketHostTcpBase::DoRead in case of error. (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 | « content/browser/renderer_host/p2p/socket_host_tcp.h ('k') | 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 "content/browser/renderer_host/p2p/socket_host_tcp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h"
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "content/common/p2p_messages.h" 8 #include "content/common/p2p_messages.h"
9 #include "ipc/ipc_sender.h" 9 #include "ipc/ipc_sender.h"
10 #include "jingle/glue/fake_ssl_client_socket.h" 10 #include "jingle/glue/fake_ssl_client_socket.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) { 227 if (net::OK != socket_->SetReceiveBufferSize(kRecvSocketBufferSize)) {
228 LOG(WARNING) << "Failed to set socket receive buffer size to " 228 LOG(WARNING) << "Failed to set socket receive buffer size to "
229 << kRecvSocketBufferSize; 229 << kRecvSocketBufferSize;
230 } 230 }
231 231
232 if (net::OK != socket_->SetSendBufferSize(kSendSocketBufferSize)) { 232 if (net::OK != socket_->SetSendBufferSize(kSendSocketBufferSize)) {
233 LOG(WARNING) << "Failed to set socket send buffer size to " 233 LOG(WARNING) << "Failed to set socket send buffer size to "
234 << kSendSocketBufferSize; 234 << kSendSocketBufferSize;
235 } 235 }
236 236
237 DoSendSocketCreateMsg(); 237 if (!DoSendSocketCreateMsg())
238 return;
239
240 DCHECK_EQ(state_, STATE_OPEN);
238 DoRead(); 241 DoRead();
239 } 242 }
240 243
241 void P2PSocketHostTcpBase::DoSendSocketCreateMsg() { 244 bool P2PSocketHostTcpBase::DoSendSocketCreateMsg() {
242 DCHECK(socket_.get()); 245 DCHECK(socket_.get());
243 246
244 net::IPEndPoint local_address; 247 net::IPEndPoint local_address;
245 int result = socket_->GetLocalAddress(&local_address); 248 int result = socket_->GetLocalAddress(&local_address);
246 if (result < 0) { 249 if (result < 0) {
247 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local" 250 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get local"
248 << " address: " << result; 251 << " address: " << result;
249 OnError(); 252 OnError();
250 return; 253 return false;
251 } 254 }
252 255
253 VLOG(1) << "Local address: " << local_address.ToString(); 256 VLOG(1) << "Local address: " << local_address.ToString();
254 257
255 net::IPEndPoint remote_address; 258 net::IPEndPoint remote_address;
256 result = socket_->GetPeerAddress(&remote_address); 259 result = socket_->GetPeerAddress(&remote_address);
257 if (result < 0) { 260 if (result < 0) {
258 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer" 261 LOG(ERROR) << "P2PSocketHostTcpBase::OnConnected: unable to get peer"
259 << " address: " << result; 262 << " address: " << result;
260 OnError(); 263 OnError();
261 return; 264 return false;
262 } 265 }
263 VLOG(1) << "Remote address: " << remote_address.ToString(); 266 VLOG(1) << "Remote address: " << remote_address.ToString();
264 if (remote_address_.ip_address.address().empty()) { 267 if (remote_address_.ip_address.address().empty()) {
265 // Save |remote_address| if address is empty. 268 // Save |remote_address| if address is empty.
266 remote_address_.ip_address = remote_address; 269 remote_address_.ip_address = remote_address;
267 } 270 }
268 271
269 // If we are not doing TLS, we are ready to send data now. 272 // If we are not doing TLS, we are ready to send data now.
270 // In case of TLS SignalConnect will be sent only after TLS handshake is 273 // In case of TLS SignalConnect will be sent only after TLS handshake is
271 // successfull. So no buffering will be done at socket handlers if any 274 // successfull. So no buffering will be done at socket handlers if any
272 // packets sent before that by the application. 275 // packets sent before that by the application.
273 message_sender_->Send(new P2PMsg_OnSocketCreated( 276 message_sender_->Send(new P2PMsg_OnSocketCreated(
274 id_, local_address, remote_address)); 277 id_, local_address, remote_address));
278 return true;
275 } 279 }
276 280
277 void P2PSocketHostTcpBase::DoRead() { 281 void P2PSocketHostTcpBase::DoRead() {
278 int result; 282 int result;
279 do { 283 do {
280 if (!read_buffer_.get()) { 284 if (!read_buffer_.get()) {
281 read_buffer_ = new net::GrowableIOBuffer(); 285 read_buffer_ = new net::GrowableIOBuffer();
282 read_buffer_->SetCapacity(kReadBufferSize); 286 read_buffer_->SetCapacity(kReadBufferSize);
283 } else if (read_buffer_->RemainingCapacity() < kReadBufferSize) { 287 } else if (read_buffer_->RemainingCapacity() < kReadBufferSize) {
284 // Make sure that we always have at least kReadBufferSize of 288 // Make sure that we always have at least kReadBufferSize of
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } else { 610 } else {
607 packet_size += kTurnChannelDataHeaderSize; 611 packet_size += kTurnChannelDataHeaderSize;
608 // Calculate any padding if present. 612 // Calculate any padding if present.
609 if (packet_size % 4) 613 if (packet_size % 4)
610 *pad_bytes = 4 - packet_size % 4; 614 *pad_bytes = 4 - packet_size % 4;
611 } 615 }
612 return packet_size; 616 return packet_size;
613 } 617 }
614 618
615 } // namespace content 619 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698