| 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 "net/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 290 | 290 |
| 291 void QuicDispatcher::DeleteSessions() { | 291 void QuicDispatcher::DeleteSessions() { |
| 292 STLDeleteElements(&closed_session_list_); | 292 STLDeleteElements(&closed_session_list_); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void QuicDispatcher::OnCanWrite() { | 295 void QuicDispatcher::OnCanWrite() { |
| 296 // We got an EPOLLOUT: the socket should not be blocked. | 296 // We got an EPOLLOUT: the socket should not be blocked. |
| 297 writer_->SetWritable(); | 297 writer_->SetWritable(); |
| 298 | 298 |
| 299 // Give each writer one attempt to write. | 299 // Give all the blocked writers one chance to write, until we're blocked again |
| 300 int num_writers = write_blocked_list_.size(); | 300 // or there's no work left. |
| 301 for (int i = 0; i < num_writers; ++i) { | 301 while (!write_blocked_list_.empty() && !writer_->IsWriteBlocked()) { |
| 302 if (write_blocked_list_.empty()) { | |
| 303 return; | |
| 304 } | |
| 305 QuicBlockedWriterInterface* blocked_writer = | 302 QuicBlockedWriterInterface* blocked_writer = |
| 306 write_blocked_list_.begin()->first; | 303 write_blocked_list_.begin()->first; |
| 307 write_blocked_list_.erase(write_blocked_list_.begin()); | 304 write_blocked_list_.erase(write_blocked_list_.begin()); |
| 308 blocked_writer->OnCanWrite(); | 305 blocked_writer->OnCanWrite(); |
| 309 if (writer_->IsWriteBlocked()) { | |
| 310 // We were unable to write. Wait for the next EPOLLOUT. The writer is | |
| 311 // responsible for adding itself to the blocked list via OnWriteBlocked(). | |
| 312 return; | |
| 313 } | |
| 314 } | 306 } |
| 315 } | 307 } |
| 316 | 308 |
| 317 bool QuicDispatcher::HasPendingWrites() const { | 309 bool QuicDispatcher::HasPendingWrites() const { |
| 318 return !write_blocked_list_.empty(); | 310 return !write_blocked_list_.empty(); |
| 319 } | 311 } |
| 320 | 312 |
| 321 void QuicDispatcher::Shutdown() { | 313 void QuicDispatcher::Shutdown() { |
| 322 while (!session_map_.empty()) { | 314 while (!session_map_.empty()) { |
| 323 QuicSession* session = session_map_.begin()->second; | 315 QuicSession* session = session_map_.begin()->second; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 345 << QuicUtils::ErrorToString(error); | 337 << QuicUtils::ErrorToString(error); |
| 346 | 338 |
| 347 if (closed_session_list_.empty()) { | 339 if (closed_session_list_.empty()) { |
| 348 epoll_server_->RegisterAlarmApproximateDelta( | 340 epoll_server_->RegisterAlarmApproximateDelta( |
| 349 0, delete_sessions_alarm_.get()); | 341 0, delete_sessions_alarm_.get()); |
| 350 } | 342 } |
| 351 closed_session_list_.push_back(it->second); | 343 closed_session_list_.push_back(it->second); |
| 352 CleanUpSession(it); | 344 CleanUpSession(it); |
| 353 } | 345 } |
| 354 | 346 |
| 355 void QuicDispatcher::OnWriteBlocked(QuicBlockedWriterInterface* writer) { | 347 void QuicDispatcher::OnWriteBlocked( |
| 356 DCHECK(writer_->IsWriteBlocked()); | 348 QuicBlockedWriterInterface* blocked_writer) { |
| 357 write_blocked_list_.insert(make_pair(writer, true)); | 349 if (!writer_->IsWriteBlocked()) { |
| 350 LOG(DFATAL) << |
| 351 "QuicDispatcher::OnWriteBlocked called when the writer is not blocked."; |
| 352 // Return without adding the connection to the blocked list, to avoid |
| 353 // infinite loops in OnCanWrite. |
| 354 return; |
| 355 } |
| 356 write_blocked_list_.insert(make_pair(blocked_writer, true)); |
| 358 } | 357 } |
| 359 | 358 |
| 360 QuicPacketWriter* QuicDispatcher::CreateWriter(int fd) { | 359 QuicPacketWriter* QuicDispatcher::CreateWriter(int fd) { |
| 361 return new QuicDefaultPacketWriter(fd); | 360 return new QuicDefaultPacketWriter(fd); |
| 362 } | 361 } |
| 363 | 362 |
| 364 QuicSession* QuicDispatcher::CreateQuicSession( | 363 QuicSession* QuicDispatcher::CreateQuicSession( |
| 365 QuicConnectionId connection_id, | 364 QuicConnectionId connection_id, |
| 366 const IPEndPoint& server_address, | 365 const IPEndPoint& server_address, |
| 367 const IPEndPoint& client_address) { | 366 const IPEndPoint& client_address) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 406 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
| 408 header.connection_id)); | 407 header.connection_id)); |
| 409 | 408 |
| 410 // Continue parsing the packet to extract the sequence number. Then | 409 // Continue parsing the packet to extract the sequence number. Then |
| 411 // send it to the time wait manager in OnUnathenticatedHeader. | 410 // send it to the time wait manager in OnUnathenticatedHeader. |
| 412 return true; | 411 return true; |
| 413 } | 412 } |
| 414 | 413 |
| 415 } // namespace tools | 414 } // namespace tools |
| 416 } // namespace net | 415 } // namespace net |
| OLD | NEW |