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/core/quic_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 ++stats_.packets_discarded; | 1600 ++stats_.packets_discarded; |
1601 return true; | 1601 return true; |
1602 } | 1602 } |
1603 // Termination packets are encrypted and saved, so don't exit early. | 1603 // Termination packets are encrypted and saved, so don't exit early. |
1604 const bool is_termination_packet = IsTerminationPacket(*packet); | 1604 const bool is_termination_packet = IsTerminationPacket(*packet); |
1605 if (writer_->IsWriteBlocked() && !is_termination_packet) { | 1605 if (writer_->IsWriteBlocked() && !is_termination_packet) { |
1606 return false; | 1606 return false; |
1607 } | 1607 } |
1608 | 1608 |
1609 QuicPacketNumber packet_number = packet->packet_number; | 1609 QuicPacketNumber packet_number = packet->packet_number; |
| 1610 // TODO(ianswett): Remove packet_number_of_last_sent_packet_ because it's |
| 1611 // redundant to SentPacketManager_->GetLargestPacket in most cases, and wrong |
| 1612 // for multipath. |
1610 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); | 1613 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); |
1611 packet_number_of_last_sent_packet_ = packet_number; | 1614 packet_number_of_last_sent_packet_ = packet_number; |
1612 | 1615 |
1613 QuicPacketLength encrypted_length = packet->encrypted_length; | 1616 QuicPacketLength encrypted_length = packet->encrypted_length; |
1614 // Termination packets are eventually owned by TimeWaitListManager. | 1617 // Termination packets are eventually owned by TimeWaitListManager. |
1615 // Others are deleted at the end of this call. | 1618 // Others are deleted at the end of this call. |
1616 if (is_termination_packet) { | 1619 if (is_termination_packet) { |
1617 if (termination_packets_.get() == nullptr) { | 1620 if (termination_packets_.get() == nullptr) { |
1618 termination_packets_.reset( | 1621 termination_packets_.reset( |
1619 new std::vector<std::unique_ptr<QuicEncryptedPacket>>); | 1622 new std::vector<std::unique_ptr<QuicEncryptedPacket>>); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 if (result.status == WRITE_STATUS_BLOCKED) { | 1660 if (result.status == WRITE_STATUS_BLOCKED) { |
1658 visitor_->OnWriteBlocked(); | 1661 visitor_->OnWriteBlocked(); |
1659 // If the socket buffers the the data, then the packet should not | 1662 // If the socket buffers the the data, then the packet should not |
1660 // be queued and sent again, which would result in an unnecessary | 1663 // be queued and sent again, which would result in an unnecessary |
1661 // duplicate packet being sent. The helper must call OnCanWrite | 1664 // duplicate packet being sent. The helper must call OnCanWrite |
1662 // when the write completes, and OnWriteError if an error occurs. | 1665 // when the write completes, and OnWriteError if an error occurs. |
1663 if (!writer_->IsWriteBlockedDataBuffered()) { | 1666 if (!writer_->IsWriteBlockedDataBuffered()) { |
1664 return false; | 1667 return false; |
1665 } | 1668 } |
1666 } | 1669 } |
| 1670 |
| 1671 if (FLAGS_quic_only_track_sent_packets) { |
| 1672 // In some cases, an MTU probe can cause EMSGSIZE. This indicates that the |
| 1673 // MTU discovery is permanently unsuccessful. |
| 1674 if (FLAGS_graceful_emsgsize_on_mtu_probe && |
| 1675 result.status == WRITE_STATUS_ERROR && |
| 1676 result.error_code == kMessageTooBigErrorCode && |
| 1677 packet->retransmittable_frames.empty() && |
| 1678 packet->encrypted_length > long_term_mtu_) { |
| 1679 mtu_discovery_target_ = 0; |
| 1680 mtu_discovery_alarm_->Cancel(); |
| 1681 // The write failed, but the writer is not blocked, so return true. |
| 1682 return true; |
| 1683 } |
| 1684 |
| 1685 if (result.status == WRITE_STATUS_ERROR) { |
| 1686 OnWriteError(result.error_code); |
| 1687 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length |
| 1688 << " from host " |
| 1689 << (self_address().address().empty() |
| 1690 ? " empty address " |
| 1691 : self_address().ToStringWithoutPort()) |
| 1692 << " to address " << peer_address().ToString() |
| 1693 << " with error code " << result.error_code; |
| 1694 return false; |
| 1695 } |
| 1696 } |
| 1697 |
1667 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { | 1698 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { |
1668 // Pass the write result to the visitor. | 1699 // Pass the write result to the visitor. |
1669 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, | 1700 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, |
1670 packet->original_packet_number, | 1701 packet->original_packet_number, |
1671 packet->transmission_type, packet_send_time); | 1702 packet->transmission_type, packet_send_time); |
1672 } | 1703 } |
1673 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1704 if (packet->transmission_type == NOT_RETRANSMISSION) { |
1674 time_of_last_sent_new_packet_ = packet_send_time; | 1705 time_of_last_sent_new_packet_ = packet_send_time; |
1675 if (!FLAGS_quic_better_last_send_for_timeout) { | 1706 if (!FLAGS_quic_better_last_send_for_timeout) { |
1676 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | 1707 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 sent_packet_manager_->GetLeastUnacked(packet->path_id), | 1739 sent_packet_manager_->GetLeastUnacked(packet->path_id), |
1709 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); | 1740 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); |
1710 | 1741 |
1711 stats_.bytes_sent += result.bytes_written; | 1742 stats_.bytes_sent += result.bytes_written; |
1712 ++stats_.packets_sent; | 1743 ++stats_.packets_sent; |
1713 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1744 if (packet->transmission_type != NOT_RETRANSMISSION) { |
1714 stats_.bytes_retransmitted += result.bytes_written; | 1745 stats_.bytes_retransmitted += result.bytes_written; |
1715 ++stats_.packets_retransmitted; | 1746 ++stats_.packets_retransmitted; |
1716 } | 1747 } |
1717 | 1748 |
1718 // In some cases, an MTU probe can cause ERR_MSG_TOO_BIG. This indicates that | 1749 if (!FLAGS_quic_only_track_sent_packets) { |
1719 // the MTU discovery is permanently unsuccessful. | 1750 // In some cases, an MTU probe can cause EMSGSIZE. This indicates that the |
1720 if (FLAGS_graceful_emsgsize_on_mtu_probe && | 1751 // MTU discovery is permanently unsuccessful. |
1721 result.status == WRITE_STATUS_ERROR && | 1752 if (FLAGS_graceful_emsgsize_on_mtu_probe && |
1722 result.error_code == kMessageTooBigErrorCode && | 1753 result.status == WRITE_STATUS_ERROR && |
1723 packet->retransmittable_frames.empty() && | 1754 result.error_code == kMessageTooBigErrorCode && |
1724 packet->encrypted_length > long_term_mtu_) { | 1755 packet->retransmittable_frames.empty() && |
1725 mtu_discovery_target_ = 0; | 1756 packet->encrypted_length > long_term_mtu_) { |
1726 mtu_discovery_alarm_->Cancel(); | 1757 mtu_discovery_target_ = 0; |
1727 return true; | 1758 mtu_discovery_alarm_->Cancel(); |
1728 } | 1759 return true; |
| 1760 } |
1729 | 1761 |
1730 if (result.status == WRITE_STATUS_ERROR) { | 1762 if (result.status == WRITE_STATUS_ERROR) { |
1731 OnWriteError(result.error_code); | 1763 OnWriteError(result.error_code); |
1732 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length | 1764 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length |
1733 << " bytes " | 1765 << " from host " |
1734 << " from host " << (self_address().address().empty() | 1766 << (self_address().address().empty() |
1735 ? " empty address " | 1767 ? " empty address " |
1736 : self_address().ToStringWithoutPort()) | 1768 : self_address().ToStringWithoutPort()) |
1737 << " to address " << peer_address().ToString() | 1769 << " to address " << peer_address().ToString() |
1738 << " with error code " << result.error_code; | 1770 << " with error code " << result.error_code; |
1739 return false; | 1771 return false; |
| 1772 } |
1740 } | 1773 } |
1741 | 1774 |
1742 return true; | 1775 return true; |
1743 } | 1776 } |
1744 | 1777 |
1745 bool QuicConnection::ShouldDiscardPacket(const SerializedPacket& packet) { | 1778 bool QuicConnection::ShouldDiscardPacket(const SerializedPacket& packet) { |
1746 if (!connected_) { | 1779 if (!connected_) { |
1747 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; | 1780 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; |
1748 return true; | 1781 return true; |
1749 } | 1782 } |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 | 2559 |
2527 void QuicConnection::CheckIfApplicationLimited() { | 2560 void QuicConnection::CheckIfApplicationLimited() { |
2528 if (queued_packets_.empty() && | 2561 if (queued_packets_.empty() && |
2529 !sent_packet_manager_->HasPendingRetransmissions() && | 2562 !sent_packet_manager_->HasPendingRetransmissions() && |
2530 !visitor_->WillingAndAbleToWrite()) { | 2563 !visitor_->WillingAndAbleToWrite()) { |
2531 sent_packet_manager_->OnApplicationLimited(); | 2564 sent_packet_manager_->OnApplicationLimited(); |
2532 } | 2565 } |
2533 } | 2566 } |
2534 | 2567 |
2535 } // namespace net | 2568 } // namespace net |
OLD | NEW |