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 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 visitor_->OnWriteBlocked(); | 1692 visitor_->OnWriteBlocked(); |
1693 // If the socket buffers the the data, then the packet should not | 1693 // If the socket buffers the the data, then the packet should not |
1694 // be queued and sent again, which would result in an unnecessary | 1694 // be queued and sent again, which would result in an unnecessary |
1695 // duplicate packet being sent. The helper must call OnCanWrite | 1695 // duplicate packet being sent. The helper must call OnCanWrite |
1696 // when the write completes, and OnWriteError if an error occurs. | 1696 // when the write completes, and OnWriteError if an error occurs. |
1697 if (!writer_->IsWriteBlockedDataBuffered()) { | 1697 if (!writer_->IsWriteBlockedDataBuffered()) { |
1698 return false; | 1698 return false; |
1699 } | 1699 } |
1700 } | 1700 } |
1701 | 1701 |
1702 if (FLAGS_quic_only_track_sent_packets) { | 1702 // In some cases, an MTU probe can cause EMSGSIZE. This indicates that the |
1703 // In some cases, an MTU probe can cause EMSGSIZE. This indicates that the | 1703 // MTU discovery is permanently unsuccessful. |
1704 // MTU discovery is permanently unsuccessful. | 1704 if (result.status == WRITE_STATUS_ERROR && |
1705 if (result.status == WRITE_STATUS_ERROR && | 1705 result.error_code == kMessageTooBigErrorCode && |
1706 result.error_code == kMessageTooBigErrorCode && | 1706 packet->retransmittable_frames.empty() && |
1707 packet->retransmittable_frames.empty() && | 1707 packet->encrypted_length > long_term_mtu_) { |
1708 packet->encrypted_length > long_term_mtu_) { | 1708 mtu_discovery_target_ = 0; |
1709 mtu_discovery_target_ = 0; | 1709 mtu_discovery_alarm_->Cancel(); |
1710 mtu_discovery_alarm_->Cancel(); | 1710 // The write failed, but the writer is not blocked, so return true. |
1711 // The write failed, but the writer is not blocked, so return true. | 1711 return true; |
1712 return true; | 1712 } |
1713 } | |
1714 | 1713 |
1715 if (result.status == WRITE_STATUS_ERROR) { | 1714 if (result.status == WRITE_STATUS_ERROR) { |
1716 OnWriteError(result.error_code); | 1715 OnWriteError(result.error_code); |
1717 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length | 1716 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length |
1718 << " from host " | 1717 << " from host " << (self_address().address().empty() |
1719 << (self_address().address().empty() | 1718 ? " empty address " |
1720 ? " empty address " | 1719 : self_address().ToStringWithoutPort()) |
1721 : self_address().ToStringWithoutPort()) | 1720 << " to address " << peer_address().ToString() |
1722 << " to address " << peer_address().ToString() | 1721 << " with error code " << result.error_code; |
1723 << " with error code " << result.error_code; | 1722 return false; |
1724 return false; | |
1725 } | |
1726 } | 1723 } |
1727 | 1724 |
1728 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { | 1725 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { |
1729 // Pass the write result to the visitor. | 1726 // Pass the write result to the visitor. |
1730 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, | 1727 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, |
1731 packet->original_packet_number, | 1728 packet->original_packet_number, |
1732 packet->transmission_type, packet_send_time); | 1729 packet->transmission_type, packet_send_time); |
1733 } | 1730 } |
1734 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1731 if (packet->transmission_type == NOT_RETRANSMISSION) { |
1735 time_of_last_sent_new_packet_ = packet_send_time; | 1732 time_of_last_sent_new_packet_ = packet_send_time; |
(...skipping 25 matching lines...) Expand all Loading... |
1761 sent_packet_manager_->GetLeastUnacked(packet->path_id), | 1758 sent_packet_manager_->GetLeastUnacked(packet->path_id), |
1762 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); | 1759 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); |
1763 | 1760 |
1764 stats_.bytes_sent += result.bytes_written; | 1761 stats_.bytes_sent += result.bytes_written; |
1765 ++stats_.packets_sent; | 1762 ++stats_.packets_sent; |
1766 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1763 if (packet->transmission_type != NOT_RETRANSMISSION) { |
1767 stats_.bytes_retransmitted += result.bytes_written; | 1764 stats_.bytes_retransmitted += result.bytes_written; |
1768 ++stats_.packets_retransmitted; | 1765 ++stats_.packets_retransmitted; |
1769 } | 1766 } |
1770 | 1767 |
1771 if (!FLAGS_quic_only_track_sent_packets) { | |
1772 // In some cases, an MTU probe can cause EMSGSIZE. This indicates that the | |
1773 // MTU discovery is permanently unsuccessful. | |
1774 if (result.status == WRITE_STATUS_ERROR && | |
1775 result.error_code == kMessageTooBigErrorCode && | |
1776 packet->retransmittable_frames.empty() && | |
1777 packet->encrypted_length > long_term_mtu_) { | |
1778 mtu_discovery_target_ = 0; | |
1779 mtu_discovery_alarm_->Cancel(); | |
1780 return true; | |
1781 } | |
1782 | |
1783 if (result.status == WRITE_STATUS_ERROR) { | |
1784 OnWriteError(result.error_code); | |
1785 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length | |
1786 << " from host " | |
1787 << (self_address().address().empty() | |
1788 ? " empty address " | |
1789 : self_address().ToStringWithoutPort()) | |
1790 << " to address " << peer_address().ToString() | |
1791 << " with error code " << result.error_code; | |
1792 return false; | |
1793 } | |
1794 } | |
1795 | |
1796 return true; | 1768 return true; |
1797 } | 1769 } |
1798 | 1770 |
1799 bool QuicConnection::ShouldDiscardPacket(const SerializedPacket& packet) { | 1771 bool QuicConnection::ShouldDiscardPacket(const SerializedPacket& packet) { |
1800 if (!connected_) { | 1772 if (!connected_) { |
1801 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; | 1773 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; |
1802 return true; | 1774 return true; |
1803 } | 1775 } |
1804 | 1776 |
1805 QuicPacketNumber packet_number = packet.packet_number; | 1777 QuicPacketNumber packet_number = packet.packet_number; |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 | 2555 |
2584 void QuicConnection::CheckIfApplicationLimited() { | 2556 void QuicConnection::CheckIfApplicationLimited() { |
2585 if (queued_packets_.empty() && | 2557 if (queued_packets_.empty() && |
2586 !sent_packet_manager_->HasPendingRetransmissions() && | 2558 !sent_packet_manager_->HasPendingRetransmissions() && |
2587 !visitor_->WillingAndAbleToWrite()) { | 2559 !visitor_->WillingAndAbleToWrite()) { |
2588 sent_packet_manager_->OnApplicationLimited(); | 2560 sent_packet_manager_->OnApplicationLimited(); |
2589 } | 2561 } |
2590 } | 2562 } |
2591 | 2563 |
2592 } // namespace net | 2564 } // namespace net |
OLD | NEW |