| 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/tools/quic/quic_simple_client.h" | 5 #include "net/tools/quic/quic_simple_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 initialized_(false), | 71 initialized_(false), |
| 72 packet_reader_started_(false), | 72 packet_reader_started_(false), |
| 73 weak_factory_(this) {} | 73 weak_factory_(this) {} |
| 74 | 74 |
| 75 QuicSimpleClient::~QuicSimpleClient() { | 75 QuicSimpleClient::~QuicSimpleClient() { |
| 76 if (connected()) { | 76 if (connected()) { |
| 77 session()->connection()->CloseConnection( | 77 session()->connection()->CloseConnection( |
| 78 QUIC_PEER_GOING_AWAY, "Shutting down", | 78 QUIC_PEER_GOING_AWAY, "Shutting down", |
| 79 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 79 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 80 } | 80 } |
| 81 STLDeleteElements(&data_to_resend_on_connect_); | 81 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 82 STLDeleteElements(&data_sent_before_handshake_); | 82 base::STLDeleteElements(&data_sent_before_handshake_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool QuicSimpleClient::Initialize() { | 85 bool QuicSimpleClient::Initialize() { |
| 86 DCHECK(!initialized_); | 86 DCHECK(!initialized_); |
| 87 | 87 |
| 88 QuicClientBase::Initialize(); | 88 QuicClientBase::Initialize(); |
| 89 | 89 |
| 90 if (!CreateUDPSocket()) { | 90 if (!CreateUDPSocket()) { |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 while (EncryptionBeingEstablished()) { | 174 while (EncryptionBeingEstablished()) { |
| 175 WaitForEvents(); | 175 WaitForEvents(); |
| 176 } | 176 } |
| 177 if (FLAGS_enable_quic_stateless_reject_support && connected() && | 177 if (FLAGS_enable_quic_stateless_reject_support && connected() && |
| 178 !data_to_resend_on_connect_.empty()) { | 178 !data_to_resend_on_connect_.empty()) { |
| 179 // A connection has been established and there was previously queued data | 179 // A connection has been established and there was previously queued data |
| 180 // to resend. Resend it and empty the queue. | 180 // to resend. Resend it and empty the queue. |
| 181 for (QuicDataToResend* data : data_to_resend_on_connect_) { | 181 for (QuicDataToResend* data : data_to_resend_on_connect_) { |
| 182 data->Resend(); | 182 data->Resend(); |
| 183 } | 183 } |
| 184 STLDeleteElements(&data_to_resend_on_connect_); | 184 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 185 } | 185 } |
| 186 if (session() != nullptr && | 186 if (session() != nullptr && |
| 187 session()->error() != QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { | 187 session()->error() != QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { |
| 188 // We've successfully created a session but we're not connected, and there | 188 // We've successfully created a session but we're not connected, and there |
| 189 // is no stateless reject to recover from. Give up trying. | 189 // is no stateless reject to recover from. Give up trying. |
| 190 break; | 190 break; |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 if (!connected() && | 193 if (!connected() && |
| 194 GetNumSentClientHellos() > QuicCryptoClientStream::kMaxClientHellos && | 194 GetNumSentClientHellos() > QuicCryptoClientStream::kMaxClientHellos && |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 void QuicSimpleClient::Disconnect() { | 233 void QuicSimpleClient::Disconnect() { |
| 234 DCHECK(initialized_); | 234 DCHECK(initialized_); |
| 235 | 235 |
| 236 if (connected()) { | 236 if (connected()) { |
| 237 session()->connection()->CloseConnection( | 237 session()->connection()->CloseConnection( |
| 238 QUIC_PEER_GOING_AWAY, "Client disconnecting", | 238 QUIC_PEER_GOING_AWAY, "Client disconnecting", |
| 239 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 239 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 240 } | 240 } |
| 241 STLDeleteElements(&data_to_resend_on_connect_); | 241 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 242 STLDeleteElements(&data_sent_before_handshake_); | 242 base::STLDeleteElements(&data_sent_before_handshake_); |
| 243 | 243 |
| 244 reset_writer(); | 244 reset_writer(); |
| 245 packet_reader_.reset(); | 245 packet_reader_.reset(); |
| 246 packet_reader_started_ = false; | 246 packet_reader_started_ = false; |
| 247 | 247 |
| 248 initialized_ = false; | 248 initialized_ = false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 void QuicSimpleClient::SendRequest(const HttpRequestInfo& headers, | 251 void QuicSimpleClient::SendRequest(const HttpRequestInfo& headers, |
| 252 base::StringPiece body, | 252 base::StringPiece body, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 MaybeAddQuicDataToResend(data_to_resend); | 270 MaybeAddQuicDataToResend(data_to_resend); |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 void QuicSimpleClient::MaybeAddQuicDataToResend( | 274 void QuicSimpleClient::MaybeAddQuicDataToResend( |
| 275 QuicDataToResend* data_to_resend) { | 275 QuicDataToResend* data_to_resend) { |
| 276 DCHECK(FLAGS_enable_quic_stateless_reject_support); | 276 DCHECK(FLAGS_enable_quic_stateless_reject_support); |
| 277 if (session()->IsCryptoHandshakeConfirmed()) { | 277 if (session()->IsCryptoHandshakeConfirmed()) { |
| 278 // The handshake is confirmed. No need to continue saving requests to | 278 // The handshake is confirmed. No need to continue saving requests to |
| 279 // resend. | 279 // resend. |
| 280 STLDeleteElements(&data_sent_before_handshake_); | 280 base::STLDeleteElements(&data_sent_before_handshake_); |
| 281 delete data_to_resend; | 281 delete data_to_resend; |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // The handshake is not confirmed. Push the data onto the queue of data to | 285 // The handshake is not confirmed. Push the data onto the queue of data to |
| 286 // resend if statelessly rejected. | 286 // resend if statelessly rejected. |
| 287 data_sent_before_handshake_.push_back(data_to_resend); | 287 data_sent_before_handshake_.push_back(data_to_resend); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void QuicSimpleClient::SendRequestAndWaitForResponse( | 290 void QuicSimpleClient::SendRequestAndWaitForResponse( |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 session()->connection()->ProcessUdpPacket(local_address, peer_address, | 408 session()->connection()->ProcessUdpPacket(local_address, peer_address, |
| 409 packet); | 409 packet); |
| 410 if (!session()->connection()->connected()) { | 410 if (!session()->connection()->connected()) { |
| 411 return false; | 411 return false; |
| 412 } | 412 } |
| 413 | 413 |
| 414 return true; | 414 return true; |
| 415 } | 415 } |
| 416 | 416 |
| 417 } // namespace net | 417 } // namespace net |
| OLD | NEW |