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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 sent_packet_manager_.NextPendingRetransmission(); | 1234 sent_packet_manager_.NextPendingRetransmission(); |
1235 if (GetPacketType(&pending.retransmittable_frames) == NORMAL && | 1235 if (GetPacketType(&pending.retransmittable_frames) == NORMAL && |
1236 !CanWrite(HAS_RETRANSMITTABLE_DATA)) { | 1236 !CanWrite(HAS_RETRANSMITTABLE_DATA)) { |
1237 break; | 1237 break; |
1238 } | 1238 } |
1239 | 1239 |
1240 // Re-packetize the frames with a new sequence number for retransmission. | 1240 // Re-packetize the frames with a new sequence number for retransmission. |
1241 // Retransmitted data packets do not use FEC, even when it's enabled. | 1241 // Retransmitted data packets do not use FEC, even when it's enabled. |
1242 // Retransmitted packets use the same sequence number length as the | 1242 // Retransmitted packets use the same sequence number length as the |
1243 // original. | 1243 // original. |
1244 // Flush the packet creator before making a new packet. | 1244 // Flush the packet generator before making a new packet. |
1245 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that | 1245 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that |
1246 // does not require the creator to be flushed. | 1246 // does not require the creator to be flushed. |
1247 Flush(); | 1247 packet_generator_.FlushAllQueuedFrames(); |
1248 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( | 1248 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( |
1249 pending.retransmittable_frames.frames(), | 1249 pending.retransmittable_frames.frames(), |
1250 pending.sequence_number_length); | 1250 pending.sequence_number_length); |
1251 | 1251 |
1252 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number | 1252 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number |
1253 << " as " << serialized_packet.sequence_number; | 1253 << " as " << serialized_packet.sequence_number; |
1254 if (debug_visitor_) { | 1254 if (debug_visitor_) { |
1255 debug_visitor_->OnPacketRetransmitted( | 1255 debug_visitor_->OnPacketRetransmitted( |
1256 pending.sequence_number, serialized_packet.sequence_number); | 1256 pending.sequence_number, serialized_packet.sequence_number); |
1257 } | 1257 } |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, | 1773 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, |
1774 const string& details) { | 1774 const string& details) { |
1775 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() | 1775 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() |
1776 << " with error " << QuicUtils::ErrorToString(error) | 1776 << " with error " << QuicUtils::ErrorToString(error) |
1777 << " (" << error << ") " << details; | 1777 << " (" << error << ") " << details; |
1778 ScopedPacketBundler ack_bundler(this, SEND_ACK); | 1778 ScopedPacketBundler ack_bundler(this, SEND_ACK); |
1779 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 1779 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
1780 frame->error_code = error; | 1780 frame->error_code = error; |
1781 frame->error_details = details; | 1781 frame->error_details = details; |
1782 packet_generator_.AddControlFrame(QuicFrame(frame)); | 1782 packet_generator_.AddControlFrame(QuicFrame(frame)); |
1783 Flush(); | 1783 packet_generator_.FlushAllQueuedFrames(); |
1784 } | 1784 } |
1785 | 1785 |
1786 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { | 1786 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { |
1787 if (!connected_) { | 1787 if (!connected_) { |
1788 DLOG(DFATAL) << "Error: attempt to close an already closed connection" | 1788 DLOG(DFATAL) << "Error: attempt to close an already closed connection" |
1789 << base::debug::StackTrace().ToString(); | 1789 << base::debug::StackTrace().ToString(); |
1790 return; | 1790 return; |
1791 } | 1791 } |
1792 connected_ = false; | 1792 connected_ = false; |
1793 visitor_->OnConnectionClosed(error, from_peer); | 1793 visitor_->OnConnectionClosed(error, from_peer); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 } | 1835 } |
1836 | 1836 |
1837 size_t QuicConnection::max_packet_length() const { | 1837 size_t QuicConnection::max_packet_length() const { |
1838 return packet_generator_.max_packet_length(); | 1838 return packet_generator_.max_packet_length(); |
1839 } | 1839 } |
1840 | 1840 |
1841 void QuicConnection::set_max_packet_length(size_t length) { | 1841 void QuicConnection::set_max_packet_length(size_t length) { |
1842 return packet_generator_.set_max_packet_length(length); | 1842 return packet_generator_.set_max_packet_length(length); |
1843 } | 1843 } |
1844 | 1844 |
1845 void QuicConnection::Flush() { | |
1846 packet_generator_.FlushAllQueuedFrames(); | |
1847 } | |
1848 | |
1849 bool QuicConnection::HasQueuedData() const { | 1845 bool QuicConnection::HasQueuedData() const { |
1850 return pending_version_negotiation_packet_ || | 1846 return pending_version_negotiation_packet_ || |
1851 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); | 1847 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); |
1852 } | 1848 } |
1853 | 1849 |
1854 bool QuicConnection::CanWriteStreamData() { | 1850 bool QuicConnection::CanWriteStreamData() { |
1855 // Don't write stream data if there are negotiation or queued data packets | 1851 // Don't write stream data if there are negotiation or queued data packets |
1856 // to send. Otherwise, continue and bundle as many frames as possible. | 1852 // to send. Otherwise, continue and bundle as many frames as possible. |
1857 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) { | 1853 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) { |
1858 return false; | 1854 return false; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1981 // If we changed the generator's batch state, restore original batch state. | 1977 // If we changed the generator's batch state, restore original batch state. |
1982 if (!already_in_batch_mode_) { | 1978 if (!already_in_batch_mode_) { |
1983 DVLOG(1) << "Leaving Batch Mode."; | 1979 DVLOG(1) << "Leaving Batch Mode."; |
1984 connection_->packet_generator_.FinishBatchOperations(); | 1980 connection_->packet_generator_.FinishBatchOperations(); |
1985 } | 1981 } |
1986 DCHECK_EQ(already_in_batch_mode_, | 1982 DCHECK_EQ(already_in_batch_mode_, |
1987 connection_->packet_generator_.InBatchMode()); | 1983 connection_->packet_generator_.InBatchMode()); |
1988 } | 1984 } |
1989 | 1985 |
1990 } // namespace net | 1986 } // namespace net |
OLD | NEW |