| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_server.h" | 5 #include "net/tools/quic/quic_simple_server.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // Allocate some extra space so we can send an error if the client goes over | 33 // Allocate some extra space so we can send an error if the client goes over |
| 34 // the limit. | 34 // the limit. |
| 35 const int kReadBufferSize = 2 * kMaxPacketSize; | 35 const int kReadBufferSize = 2 * kMaxPacketSize; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 QuicSimpleServer::QuicSimpleServer( | 39 QuicSimpleServer::QuicSimpleServer( |
| 40 std::unique_ptr<ProofSource> proof_source, | 40 std::unique_ptr<ProofSource> proof_source, |
| 41 const QuicConfig& config, | 41 const QuicConfig& config, |
| 42 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, | 42 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, |
| 43 const QuicVersionVector& supported_versions) | 43 const QuicVersionVector& supported_versions, |
| 44 QuicInMemoryCache* in_memory_cache) |
| 44 : version_manager_(supported_versions), | 45 : version_manager_(supported_versions), |
| 45 helper_( | 46 helper_( |
| 46 new QuicChromiumConnectionHelper(&clock_, QuicRandom::GetInstance())), | 47 new QuicChromiumConnectionHelper(&clock_, QuicRandom::GetInstance())), |
| 47 alarm_factory_(new QuicChromiumAlarmFactory( | 48 alarm_factory_(new QuicChromiumAlarmFactory( |
| 48 base::ThreadTaskRunnerHandle::Get().get(), | 49 base::ThreadTaskRunnerHandle::Get().get(), |
| 49 &clock_)), | 50 &clock_)), |
| 50 config_(config), | 51 config_(config), |
| 51 crypto_config_options_(crypto_config_options), | 52 crypto_config_options_(crypto_config_options), |
| 52 crypto_config_(kSourceAddressTokenSecret, | 53 crypto_config_(kSourceAddressTokenSecret, |
| 53 QuicRandom::GetInstance(), | 54 QuicRandom::GetInstance(), |
| 54 std::move(proof_source)), | 55 std::move(proof_source)), |
| 55 read_pending_(false), | 56 read_pending_(false), |
| 56 synchronous_read_count_(0), | 57 synchronous_read_count_(0), |
| 57 read_buffer_(new IOBufferWithSize(kReadBufferSize)), | 58 read_buffer_(new IOBufferWithSize(kReadBufferSize)), |
| 59 in_memory_cache_(in_memory_cache), |
| 58 weak_factory_(this) { | 60 weak_factory_(this) { |
| 59 Initialize(); | 61 Initialize(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void QuicSimpleServer::Initialize() { | 64 void QuicSimpleServer::Initialize() { |
| 63 #if MMSG_MORE | 65 #if MMSG_MORE |
| 64 use_recvmmsg_ = true; | 66 use_recvmmsg_ = true; |
| 65 #endif | 67 #endif |
| 66 | 68 |
| 67 // If an initial flow control window has not explicitly been set, then use a | 69 // If an initial flow control window has not explicitly been set, then use a |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 124 |
| 123 DVLOG(1) << "Listening on " << server_address_.ToString(); | 125 DVLOG(1) << "Listening on " << server_address_.ToString(); |
| 124 | 126 |
| 125 socket_.swap(socket); | 127 socket_.swap(socket); |
| 126 | 128 |
| 127 dispatcher_.reset(new QuicSimpleDispatcher( | 129 dispatcher_.reset(new QuicSimpleDispatcher( |
| 128 config_, &crypto_config_, &version_manager_, | 130 config_, &crypto_config_, &version_manager_, |
| 129 std::unique_ptr<QuicConnectionHelperInterface>(helper_), | 131 std::unique_ptr<QuicConnectionHelperInterface>(helper_), |
| 130 std::unique_ptr<QuicCryptoServerStream::Helper>( | 132 std::unique_ptr<QuicCryptoServerStream::Helper>( |
| 131 new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), | 133 new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), |
| 132 std::unique_ptr<QuicAlarmFactory>(alarm_factory_))); | 134 std::unique_ptr<QuicAlarmFactory>(alarm_factory_), in_memory_cache_)); |
| 133 QuicSimpleServerPacketWriter* writer = | 135 QuicSimpleServerPacketWriter* writer = |
| 134 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); | 136 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); |
| 135 dispatcher_->InitializeWithWriter(writer); | 137 dispatcher_->InitializeWithWriter(writer); |
| 136 | 138 |
| 137 StartReading(); | 139 StartReading(); |
| 138 | 140 |
| 139 return OK; | 141 return OK; |
| 140 } | 142 } |
| 141 | 143 |
| 142 void QuicSimpleServer::Shutdown() { | 144 void QuicSimpleServer::Shutdown() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 QuicReceivedPacket packet(read_buffer_->data(), result, | 202 QuicReceivedPacket packet(read_buffer_->data(), result, |
| 201 helper_->GetClock()->Now(), false); | 203 helper_->GetClock()->Now(), false); |
| 202 dispatcher_->ProcessPacket( | 204 dispatcher_->ProcessPacket( |
| 203 QuicSocketAddress(QuicSocketAddressImpl(server_address_)), | 205 QuicSocketAddress(QuicSocketAddressImpl(server_address_)), |
| 204 QuicSocketAddress(QuicSocketAddressImpl(client_address_)), packet); | 206 QuicSocketAddress(QuicSocketAddressImpl(client_address_)), packet); |
| 205 | 207 |
| 206 StartReading(); | 208 StartReading(); |
| 207 } | 209 } |
| 208 | 210 |
| 209 } // namespace net | 211 } // namespace net |
| OLD | NEW |