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

Side by Side Diff: net/quic/quic_dispatcher.cc

Issue 359653003: Simplify the QuicDispatcher::OnCanWrite logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed wtc's comments in Patch Set 1 Created 6 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_dispatcher.h ('k') | net/quic/quic_server_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/quic/quic_dispatcher.h" 5 #include "net/quic/quic_dispatcher.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 285 }
286 286
287 void QuicDispatcher::DeleteSessions() { 287 void QuicDispatcher::DeleteSessions() {
288 STLDeleteElements(&closed_session_list_); 288 STLDeleteElements(&closed_session_list_);
289 } 289 }
290 290
291 void QuicDispatcher::OnCanWrite() { 291 void QuicDispatcher::OnCanWrite() {
292 // We finished a write: the socket should not be blocked. 292 // We finished a write: the socket should not be blocked.
293 writer_->SetWritable(); 293 writer_->SetWritable();
294 294
295 // Let all the blocked writers try to write, until we're blocked again or 295 // Give all the blocked writers one chance to write, until we're blocked again
296 // there's no work left. 296 // or there's no work left.
297 while (!write_blocked_list_.empty() && !writer_->IsWriteBlocked()) { 297 while (!write_blocked_list_.empty() && !writer_->IsWriteBlocked()) {
298 QuicBlockedWriterInterface* blocked_writer = 298 QuicBlockedWriterInterface* blocked_writer =
299 write_blocked_list_.begin()->first; 299 write_blocked_list_.begin()->first;
300 write_blocked_list_.erase(write_blocked_list_.begin()); 300 write_blocked_list_.erase(write_blocked_list_.begin());
301 blocked_writer->OnCanWrite(); 301 blocked_writer->OnCanWrite();
302 } 302 }
303 } 303 }
304 304
305 bool QuicDispatcher::HasPendingWrites() const { 305 bool QuicDispatcher::HasPendingWrites() const {
306 return !write_blocked_list_.empty(); 306 return !write_blocked_list_.empty();
(...skipping 23 matching lines...) Expand all
330 << connection_id 330 << connection_id
331 << ") due to error: " 331 << ") due to error: "
332 << QuicUtils::ErrorToString(error); 332 << QuicUtils::ErrorToString(error);
333 if (closed_session_list_.empty()) { 333 if (closed_session_list_.empty()) {
334 delete_sessions_alarm_->Set(helper_->GetClock()->ApproximateNow()); 334 delete_sessions_alarm_->Set(helper_->GetClock()->ApproximateNow());
335 } 335 }
336 closed_session_list_.push_back(it->second); 336 closed_session_list_.push_back(it->second);
337 CleanUpSession(it); 337 CleanUpSession(it);
338 } 338 }
339 339
340 void QuicDispatcher::OnWriteBlocked(QuicBlockedWriterInterface* writer) { 340 void QuicDispatcher::OnWriteBlocked(
341 DCHECK(writer_->IsWriteBlocked()); 341 QuicBlockedWriterInterface* blocked_writer) {
342 write_blocked_list_.insert(make_pair(writer, true)); 342 if (!writer_->IsWriteBlocked()) {
343 LOG(DFATAL) <<
344 "QuicDispatcher::OnWriteBlocked called when the writer is not blocked.";
345 // Return without adding the connection to the blocked list, to avoid
346 // infinite loops in OnCanWrite.
347 return;
348 }
349 write_blocked_list_.insert(make_pair(blocked_writer, true));
343 } 350 }
344 351
345 QuicSession* QuicDispatcher::CreateQuicSession( 352 QuicSession* QuicDispatcher::CreateQuicSession(
346 QuicConnectionId connection_id, 353 QuicConnectionId connection_id,
347 const IPEndPoint& server_address, 354 const IPEndPoint& server_address,
348 const IPEndPoint& client_address) { 355 const IPEndPoint& client_address) {
349 QuicPerConnectionPacketWriter* per_connection_packet_writer = 356 QuicPerConnectionPacketWriter* per_connection_packet_writer =
350 new QuicPerConnectionPacketWriter(writer_.get()); 357 new QuicPerConnectionPacketWriter(writer_.get());
351 QuicConnection* connection = 358 QuicConnection* connection =
352 CreateQuicConnection(connection_id, 359 CreateQuicConnection(connection_id,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // be parsed correctly. 406 // be parsed correctly.
400 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( 407 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId(
401 header.connection_id)); 408 header.connection_id));
402 409
403 // Continue parsing the packet to extract the sequence number. Then 410 // Continue parsing the packet to extract the sequence number. Then
404 // send it to the time wait manager in OnUnathenticatedHeader. 411 // send it to the time wait manager in OnUnathenticatedHeader.
405 return true; 412 return true;
406 } 413 }
407 414
408 } // namespace net 415 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_dispatcher.h ('k') | net/quic/quic_server_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698