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_stream.h" | 5 #include "net/quic/core/quic_stream.h" |
6 | 6 |
7 #include "net/quic/core/quic_flow_controller.h" | 7 #include "net/quic/core/quic_flow_controller.h" |
8 #include "net/quic/core/quic_session.h" | 8 #include "net/quic/core/quic_session.h" |
9 #include "net/quic/platform/api/quic_bug_tracker.h" | 9 #include "net/quic/platform/api/quic_bug_tracker.h" |
10 #include "net/quic/platform/api/quic_logging.h" | 10 #include "net/quic/platform/api/quic_logging.h" |
11 | 11 |
12 using base::StringPiece; | |
13 using std::string; | 12 using std::string; |
14 | 13 |
15 namespace net { | 14 namespace net { |
16 | 15 |
17 #define ENDPOINT \ | 16 #define ENDPOINT \ |
18 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") | 17 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 struct iovec MakeIovec(StringPiece data) { | 21 struct iovec MakeIovec(QuicStringPiece data) { |
23 struct iovec iov = {const_cast<char*>(data.data()), | 22 struct iovec iov = {const_cast<char*>(data.data()), |
24 static_cast<size_t>(data.size())}; | 23 static_cast<size_t>(data.size())}; |
25 return iov; | 24 return iov; |
26 } | 25 } |
27 | 26 |
28 size_t GetInitialStreamFlowControlWindowToSend(QuicSession* session) { | 27 size_t GetInitialStreamFlowControlWindowToSend(QuicSession* session) { |
29 return session->config()->GetInitialStreamFlowControlWindowToSend(); | 28 return session->config()->GetInitialStreamFlowControlWindowToSend(); |
30 } | 29 } |
31 | 30 |
32 size_t GetReceivedFlowControlWindow(QuicSession* session) { | 31 size_t GetReceivedFlowControlWindow(QuicSession* session) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 rst_sent_ = true; | 174 rst_sent_ = true; |
176 } | 175 } |
177 | 176 |
178 void QuicStream::CloseConnectionWithDetails(QuicErrorCode error, | 177 void QuicStream::CloseConnectionWithDetails(QuicErrorCode error, |
179 const string& details) { | 178 const string& details) { |
180 session()->connection()->CloseConnection( | 179 session()->connection()->CloseConnection( |
181 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 180 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
182 } | 181 } |
183 | 182 |
184 void QuicStream::WriteOrBufferData( | 183 void QuicStream::WriteOrBufferData( |
185 StringPiece data, | 184 QuicStringPiece data, |
186 bool fin, | 185 bool fin, |
187 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { | 186 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
188 if (data.empty() && !fin) { | 187 if (data.empty() && !fin) { |
189 QUIC_BUG << "data.empty() && !fin"; | 188 QUIC_BUG << "data.empty() && !fin"; |
190 return; | 189 return; |
191 } | 190 } |
192 | 191 |
193 if (fin_buffered_) { | 192 if (fin_buffered_) { |
194 QUIC_BUG << "Fin already buffered"; | 193 QUIC_BUG << "Fin already buffered"; |
195 return; | 194 return; |
196 } | 195 } |
197 if (write_side_closed_) { | 196 if (write_side_closed_) { |
198 QUIC_DLOG(ERROR) << ENDPOINT | 197 QUIC_DLOG(ERROR) << ENDPOINT |
199 << "Attempt to write when the write side is closed"; | 198 << "Attempt to write when the write side is closed"; |
200 return; | 199 return; |
201 } | 200 } |
202 | 201 |
203 QuicConsumedData consumed_data(0, false); | 202 QuicConsumedData consumed_data(0, false); |
204 fin_buffered_ = fin; | 203 fin_buffered_ = fin; |
205 | 204 |
206 if (queued_data_.empty()) { | 205 if (queued_data_.empty()) { |
207 struct iovec iov(MakeIovec(data)); | 206 struct iovec iov(MakeIovec(data)); |
208 consumed_data = WritevData(&iov, 1, fin, ack_listener); | 207 consumed_data = WritevData(&iov, 1, fin, ack_listener); |
209 DCHECK_LE(consumed_data.bytes_consumed, data.length()); | 208 DCHECK_LE(consumed_data.bytes_consumed, data.length()); |
210 } | 209 } |
211 | 210 |
212 // If there's unconsumed data or an unconsumed fin, queue it. | 211 // If there's unconsumed data or an unconsumed fin, queue it. |
213 if (consumed_data.bytes_consumed < data.length() || | 212 if (consumed_data.bytes_consumed < data.length() || |
214 (fin && !consumed_data.fin_consumed)) { | 213 (fin && !consumed_data.fin_consumed)) { |
215 StringPiece remainder(data.substr(consumed_data.bytes_consumed)); | 214 QuicStringPiece remainder(data.substr(consumed_data.bytes_consumed)); |
216 queued_data_bytes_ += remainder.size(); | 215 queued_data_bytes_ += remainder.size(); |
217 queued_data_.emplace_back(remainder.as_string(), ack_listener); | 216 queued_data_.emplace_back(remainder.as_string(), ack_listener); |
218 } | 217 } |
219 } | 218 } |
220 | 219 |
221 void QuicStream::OnCanWrite() { | 220 void QuicStream::OnCanWrite() { |
222 bool fin = false; | 221 bool fin = false; |
223 while (!queued_data_.empty()) { | 222 while (!queued_data_.empty()) { |
224 PendingData* pending_data = &queued_data_.front(); | 223 PendingData* pending_data = &queued_data_.front(); |
225 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener = | 224 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener = |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 } | 479 } |
481 } | 480 } |
482 | 481 |
483 void QuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { | 482 void QuicStream::UpdateSendWindowOffset(QuicStreamOffset new_window) { |
484 if (flow_controller_.UpdateSendWindowOffset(new_window)) { | 483 if (flow_controller_.UpdateSendWindowOffset(new_window)) { |
485 OnCanWrite(); | 484 OnCanWrite(); |
486 } | 485 } |
487 } | 486 } |
488 | 487 |
489 } // namespace net | 488 } // namespace net |
OLD | NEW |