| 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_client.h" | 5 #include "net/tools/quic/quic_client.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/epoll.h> | 10 #include <sys/epoll.h> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 overflow_supported_(false), | 69 overflow_supported_(false), |
| 70 supported_versions_(supported_versions), | 70 supported_versions_(supported_versions), |
| 71 print_response_(print_response) { | 71 print_response_(print_response) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 QuicClient::~QuicClient() { | 74 QuicClient::~QuicClient() { |
| 75 if (connected()) { | 75 if (connected()) { |
| 76 session()->connection()->SendConnectionClosePacket( | 76 session()->connection()->SendConnectionClosePacket( |
| 77 QUIC_PEER_GOING_AWAY, ""); | 77 QUIC_PEER_GOING_AWAY, ""); |
| 78 } | 78 } |
| 79 if (fd_ > 0) { | 79 |
| 80 epoll_server_->UnregisterFD(fd_); | 80 CleanUpUDPSocket(); |
| 81 } | |
| 82 } | 81 } |
| 83 | 82 |
| 84 bool QuicClient::Initialize() { | 83 bool QuicClient::Initialize() { |
| 85 DCHECK(!initialized_); | 84 DCHECK(!initialized_); |
| 86 | 85 |
| 87 // If an initial flow control window has not explicitly been set, then use the | 86 // If an initial flow control window has not explicitly been set, then use the |
| 88 // same value that Chrome uses: 10 Mb. | 87 // same value that Chrome uses: 10 Mb. |
| 89 const uint32 kInitialFlowControlWindow = 10 * 1024 * 1024; // 10 Mb | 88 const uint32 kInitialFlowControlWindow = 10 * 1024 * 1024; // 10 Mb |
| 90 if (config_.GetInitialFlowControlWindowToSend() == | |
| 91 kMinimumFlowControlSendWindow) { | |
| 92 config_.SetInitialFlowControlWindowToSend(kInitialFlowControlWindow); | |
| 93 } | |
| 94 if (config_.GetInitialStreamFlowControlWindowToSend() == | 89 if (config_.GetInitialStreamFlowControlWindowToSend() == |
| 95 kMinimumFlowControlSendWindow) { | 90 kMinimumFlowControlSendWindow) { |
| 96 config_.SetInitialStreamFlowControlWindowToSend(kInitialFlowControlWindow); | 91 config_.SetInitialStreamFlowControlWindowToSend(kInitialFlowControlWindow); |
| 97 } | 92 } |
| 98 if (config_.GetInitialSessionFlowControlWindowToSend() == | 93 if (config_.GetInitialSessionFlowControlWindowToSend() == |
| 99 kMinimumFlowControlSendWindow) { | 94 kMinimumFlowControlSendWindow) { |
| 100 config_.SetInitialSessionFlowControlWindowToSend(kInitialFlowControlWindow); | 95 config_.SetInitialSessionFlowControlWindowToSend(kInitialFlowControlWindow); |
| 101 } | 96 } |
| 102 | 97 |
| 103 epoll_server_->set_timeout_in_us(50 * 1000); | 98 epoll_server_->set_timeout_in_us(50 * 1000); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 return !session_->IsEncryptionEstablished() && | 224 return !session_->IsEncryptionEstablished() && |
| 230 session_->connection()->connected(); | 225 session_->connection()->connected(); |
| 231 } | 226 } |
| 232 | 227 |
| 233 void QuicClient::Disconnect() { | 228 void QuicClient::Disconnect() { |
| 234 DCHECK(initialized_); | 229 DCHECK(initialized_); |
| 235 | 230 |
| 236 if (connected()) { | 231 if (connected()) { |
| 237 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 232 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
| 238 } | 233 } |
| 239 epoll_server_->UnregisterFD(fd_); | 234 |
| 240 close(fd_); | 235 CleanUpUDPSocket(); |
| 241 fd_ = -1; | 236 |
| 242 initialized_ = false; | 237 initialized_ = false; |
| 243 } | 238 } |
| 244 | 239 |
| 240 void QuicClient::CleanUpUDPSocket() { |
| 241 if (fd_ > -1) { |
| 242 epoll_server_->UnregisterFD(fd_); |
| 243 close(fd_); |
| 244 fd_ = -1; |
| 245 } |
| 246 } |
| 247 |
| 245 void QuicClient::SendRequestsAndWaitForResponse( | 248 void QuicClient::SendRequestsAndWaitForResponse( |
| 246 const base::CommandLine::StringVector& args) { | 249 const base::CommandLine::StringVector& args) { |
| 247 for (size_t i = 0; i < args.size(); ++i) { | 250 for (size_t i = 0; i < args.size(); ++i) { |
| 248 BalsaHeaders headers; | 251 BalsaHeaders headers; |
| 249 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); | 252 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); |
| 250 QuicSpdyClientStream* stream = CreateReliableClientStream(); | 253 QuicSpdyClientStream* stream = CreateReliableClientStream(); |
| 251 DCHECK(stream != nullptr); | 254 DCHECK(stream != nullptr); |
| 252 if (stream == nullptr) { | 255 if (stream == nullptr) { |
| 253 LOG(ERROR) << "stream creation failed!"; | 256 LOG(ERROR) << "stream creation failed!"; |
| 254 break; | 257 break; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 QuicEncryptedPacket packet(buf, bytes_read, false); | 381 QuicEncryptedPacket packet(buf, bytes_read, false); |
| 379 | 382 |
| 380 IPEndPoint client_address(client_ip, client_address_.port()); | 383 IPEndPoint client_address(client_ip, client_address_.port()); |
| 381 session_->connection()->ProcessUdpPacket( | 384 session_->connection()->ProcessUdpPacket( |
| 382 client_address, server_address, packet); | 385 client_address, server_address, packet); |
| 383 return true; | 386 return true; |
| 384 } | 387 } |
| 385 | 388 |
| 386 } // namespace tools | 389 } // namespace tools |
| 387 } // namespace net | 390 } // namespace net |
| OLD | NEW |