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/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 382 |
383 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) { | 383 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) { |
384 return true; | 384 return true; |
385 } | 385 } |
386 | 386 |
387 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { | 387 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { |
388 if (debug_visitor_) { | 388 if (debug_visitor_) { |
389 debug_visitor_->OnPacketHeader(header); | 389 debug_visitor_->OnPacketHeader(header); |
390 } | 390 } |
391 | 391 |
392 if (header.fec_flag && framer_.version() <= QUIC_VERSION_14) { | 392 if (header.fec_flag && framer_.version() == QUIC_VERSION_13) { |
393 DLOG(WARNING) << "Ignoring FEC packets for versions prior to 15."; | |
394 return false; | 393 return false; |
395 } | 394 } |
396 | 395 |
397 if (!ProcessValidatedPacket()) { | 396 if (!ProcessValidatedPacket()) { |
398 return false; | 397 return false; |
399 } | 398 } |
400 | 399 |
401 // Will be decrement below if we fall through to return true; | 400 // Will be decrement below if we fall through to return true; |
402 ++stats_.packets_dropped; | 401 ++stats_.packets_dropped; |
403 | 402 |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 | 1293 |
1295 WriteResult result = writer_->WritePacket(encrypted->data(), | 1294 WriteResult result = writer_->WritePacket(encrypted->data(), |
1296 encrypted->length(), | 1295 encrypted->length(), |
1297 self_address().address(), | 1296 self_address().address(), |
1298 peer_address()); | 1297 peer_address()); |
1299 if (result.error_code == ERR_IO_PENDING) { | 1298 if (result.error_code == ERR_IO_PENDING) { |
1300 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1299 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1301 } | 1300 } |
1302 if (debug_visitor_) { | 1301 if (debug_visitor_) { |
1303 // Pass the write result to the visitor. | 1302 // Pass the write result to the visitor. |
1304 debug_visitor_->OnPacketSent( | 1303 debug_visitor_->OnPacketSent(sequence_number, |
1305 sequence_number, packet.encryption_level, *encrypted, result); | 1304 packet.encryption_level, |
| 1305 packet.transmission_type, |
| 1306 *encrypted, |
| 1307 result); |
1306 } | 1308 } |
1307 if (result.status == WRITE_STATUS_BLOCKED) { | 1309 if (result.status == WRITE_STATUS_BLOCKED) { |
1308 visitor_->OnWriteBlocked(); | 1310 visitor_->OnWriteBlocked(); |
1309 // If the socket buffers the the data, then the packet should not | 1311 // If the socket buffers the the data, then the packet should not |
1310 // be queued and sent again, which would result in an unnecessary | 1312 // be queued and sent again, which would result in an unnecessary |
1311 // duplicate packet being sent. The helper must call OnPacketSent | 1313 // duplicate packet being sent. The helper must call OnPacketSent |
1312 // when the packet is actually sent. | 1314 // when the packet is actually sent. |
1313 if (writer_->IsWriteBlockedDataBuffered()) { | 1315 if (writer_->IsWriteBlockedDataBuffered()) { |
1314 return true; | 1316 return true; |
1315 } | 1317 } |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 | 1613 |
1612 void QuicConnection::SendConnectionClose(QuicErrorCode error) { | 1614 void QuicConnection::SendConnectionClose(QuicErrorCode error) { |
1613 SendConnectionCloseWithDetails(error, string()); | 1615 SendConnectionCloseWithDetails(error, string()); |
1614 } | 1616 } |
1615 | 1617 |
1616 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, | 1618 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, |
1617 const string& details) { | 1619 const string& details) { |
1618 // If we're write blocked, WritePacket() will not send, but will capture the | 1620 // If we're write blocked, WritePacket() will not send, but will capture the |
1619 // serialized packet. | 1621 // serialized packet. |
1620 SendConnectionClosePacket(error, details); | 1622 SendConnectionClosePacket(error, details); |
1621 CloseConnection(error, false); | 1623 if (connected_) { |
| 1624 // It's possible that while sending the connection close packet, we get a |
| 1625 // socket error and disconnect right then and there. Avoid a double |
| 1626 // disconnect in that case. |
| 1627 CloseConnection(error, false); |
| 1628 } |
1622 } | 1629 } |
1623 | 1630 |
1624 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, | 1631 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, |
1625 const string& details) { | 1632 const string& details) { |
1626 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() | 1633 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() |
1627 << " with error " << QuicUtils::ErrorToString(error) | 1634 << " with error " << QuicUtils::ErrorToString(error) |
1628 << " (" << error << ") " << details; | 1635 << " (" << error << ") " << details; |
1629 ScopedPacketBundler ack_bundler(this, SEND_ACK); | 1636 ScopedPacketBundler ack_bundler(this, SEND_ACK); |
1630 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 1637 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
1631 frame->error_code = error; | 1638 frame->error_code = error; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 // If we changed the generator's batch state, restore original batch state. | 1809 // If we changed the generator's batch state, restore original batch state. |
1803 if (!already_in_batch_mode_) { | 1810 if (!already_in_batch_mode_) { |
1804 DVLOG(1) << "Leaving Batch Mode."; | 1811 DVLOG(1) << "Leaving Batch Mode."; |
1805 connection_->packet_generator_.FinishBatchOperations(); | 1812 connection_->packet_generator_.FinishBatchOperations(); |
1806 } | 1813 } |
1807 DCHECK_EQ(already_in_batch_mode_, | 1814 DCHECK_EQ(already_in_batch_mode_, |
1808 connection_->packet_generator_.InBatchMode()); | 1815 connection_->packet_generator_.InBatchMode()); |
1809 } | 1816 } |
1810 | 1817 |
1811 } // namespace net | 1818 } // namespace net |
OLD | NEW |