| 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_packet_creator.h" | 5 #include "net/quic/quic_packet_creator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 bool include_version, | 179 bool include_version, |
| 180 bool include_path_id, | 180 bool include_path_id, |
| 181 QuicPacketNumberLength packet_number_length, | 181 QuicPacketNumberLength packet_number_length, |
| 182 QuicStreamOffset offset) { | 182 QuicStreamOffset offset) { |
| 183 return GetPacketHeaderSize(connection_id_length, include_version, | 183 return GetPacketHeaderSize(connection_id_length, include_version, |
| 184 include_path_id, packet_number_length) + | 184 include_path_id, packet_number_length) + |
| 185 // Assumes this is a stream with a single lone packet. | 185 // Assumes this is a stream with a single lone packet. |
| 186 QuicFramer::GetMinStreamFrameSize(1u, offset, true); | 186 QuicFramer::GetMinStreamFrameSize(1u, offset, true); |
| 187 } | 187 } |
| 188 | 188 |
| 189 size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, | 189 void QuicPacketCreator::CreateStreamFrame(QuicStreamId id, |
| 190 QuicIOVector iov, | 190 QuicIOVector iov, |
| 191 size_t iov_offset, | 191 size_t iov_offset, |
| 192 QuicStreamOffset offset, | 192 QuicStreamOffset offset, |
| 193 bool fin, | 193 bool fin, |
| 194 QuicFrame* frame) { | 194 QuicFrame* frame) { |
| 195 DCHECK_GT(max_packet_length_, | 195 DCHECK_GT(max_packet_length_, |
| 196 StreamFramePacketOverhead(connection_id_length_, kIncludeVersion, | 196 StreamFramePacketOverhead(connection_id_length_, kIncludeVersion, |
| 197 kIncludePathId, | 197 kIncludePathId, |
| 198 PACKET_6BYTE_PACKET_NUMBER, offset)); | 198 PACKET_6BYTE_PACKET_NUMBER, offset)); |
| 199 | 199 |
| 200 MaybeUpdatePacketNumberLength(); | 200 MaybeUpdatePacketNumberLength(); |
| 201 | 201 |
| 202 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) | 202 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) |
| 203 << "No room for Stream frame, BytesFree: " << BytesFree() | 203 << "No room for Stream frame, BytesFree: " << BytesFree() |
| 204 << " MinStreamFrameSize: " | 204 << " MinStreamFrameSize: " |
| 205 << QuicFramer::GetMinStreamFrameSize(id, offset, true); | 205 << QuicFramer::GetMinStreamFrameSize(id, offset, true); |
| 206 | 206 |
| 207 if (iov_offset == iov.total_length) { | 207 if (iov_offset == iov.total_length) { |
| 208 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin."; | 208 QUIC_BUG_IF(!fin) << "Creating a stream frame with no data or fin."; |
| 209 // Create a new packet for the fin, if necessary. | 209 // Create a new packet for the fin, if necessary. |
| 210 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, StringPiece())); | 210 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, StringPiece())); |
| 211 return 0; | 211 return; |
| 212 } | 212 } |
| 213 | 213 |
| 214 const size_t data_size = iov.total_length - iov_offset; | 214 const size_t data_size = iov.total_length - iov_offset; |
| 215 size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( | 215 size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( |
| 216 id, offset, /* last_frame_in_packet= */ true); | 216 id, offset, /* last_frame_in_packet= */ true); |
| 217 size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size); | 217 size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size); |
| 218 | 218 |
| 219 bool set_fin = fin && bytes_consumed == data_size; // Last frame. | 219 bool set_fin = fin && bytes_consumed == data_size; // Last frame. |
| 220 UniqueStreamBuffer buffer = | 220 UniqueStreamBuffer buffer = |
| 221 NewStreamBuffer(buffer_allocator_, bytes_consumed); | 221 NewStreamBuffer(buffer_allocator_, bytes_consumed); |
| 222 CopyToBuffer(iov, iov_offset, bytes_consumed, buffer.get()); | 222 CopyToBuffer(iov, iov_offset, bytes_consumed, buffer.get()); |
| 223 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, bytes_consumed, | 223 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, bytes_consumed, |
| 224 std::move(buffer))); | 224 std::move(buffer))); |
| 225 return bytes_consumed; | |
| 226 } | 225 } |
| 227 | 226 |
| 228 // static | 227 // static |
| 229 void QuicPacketCreator::CopyToBuffer(QuicIOVector iov, | 228 void QuicPacketCreator::CopyToBuffer(QuicIOVector iov, |
| 230 size_t iov_offset, | 229 size_t iov_offset, |
| 231 size_t length, | 230 size_t length, |
| 232 char* buffer) { | 231 char* buffer) { |
| 233 int iovnum = 0; | 232 int iovnum = 0; |
| 234 while (iovnum < iov.iov_count && iov_offset >= iov.iov[iovnum].iov_len) { | 233 while (iovnum < iov.iov_count && iov_offset >= iov.iov[iovnum].iov_len) { |
| 235 iov_offset -= iov.iov[iovnum].iov_len; | 234 iov_offset -= iov.iov[iovnum].iov_len; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; | 589 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; |
| 591 packet_.path_id = path_id; | 590 packet_.path_id = path_id; |
| 592 DCHECK(packet_.path_id != kInvalidPathId); | 591 DCHECK(packet_.path_id != kInvalidPathId); |
| 593 // Send path in packet if current path is not the default path. | 592 // Send path in packet if current path is not the default path. |
| 594 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; | 593 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; |
| 595 // Switching path needs to update packet number length. | 594 // Switching path needs to update packet number length. |
| 596 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); | 595 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); |
| 597 } | 596 } |
| 598 | 597 |
| 599 } // namespace net | 598 } // namespace net |
| OLD | NEW |