diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-04 14:17:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-05 10:05:06 +0000 |
commit | 39d357e3248f80abea0159765ff39554affb40db (patch) | |
tree | aba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/net/tools/quic/quic_simple_server.cc | |
parent | 87778abf5a1f89266f37d1321b92a21851d8244d (diff) | |
download | qtwebengine-chromium-39d357e3248f80abea0159765ff39554affb40db.tar.gz |
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2
Change-Id: I20d43c737f82764d857ada9a55586901b18b9243
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/net/tools/quic/quic_simple_server.cc')
-rw-r--r-- | chromium/net/tools/quic/quic_simple_server.cc | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/chromium/net/tools/quic/quic_simple_server.cc b/chromium/net/tools/quic/quic_simple_server.cc index 814feabd87e..4848cdd901c 100644 --- a/chromium/net/tools/quic/quic_simple_server.cc +++ b/chromium/net/tools/quic/quic_simple_server.cc @@ -11,12 +11,13 @@ #include "base/threading/thread_task_runner_handle.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/quic/crypto/crypto_handshake.h" -#include "net/quic/crypto/quic_random.h" -#include "net/quic/quic_crypto_stream.h" -#include "net/quic/quic_data_reader.h" -#include "net/quic/quic_protocol.h" -#include "net/tools/quic/quic_dispatcher.h" +#include "net/log/net_log_source.h" +#include "net/quic/core/crypto/crypto_handshake.h" +#include "net/quic/core/crypto/quic_random.h" +#include "net/quic/core/quic_crypto_stream.h" +#include "net/quic/core/quic_data_reader.h" +#include "net/quic/core/quic_protocol.h" +#include "net/tools/quic/quic_simple_dispatcher.h" #include "net/tools/quic/quic_simple_per_connection_packet_writer.h" #include "net/tools/quic/quic_simple_server_packet_writer.h" #include "net/tools/quic/quic_simple_server_session_helper.h" @@ -27,60 +28,30 @@ namespace net { namespace { const char kSourceAddressTokenSecret[] = "secret"; +const size_t kNumSessionsToCreatePerSocketEvent = 16; // Allocate some extra space so we can send an error if the client goes over // the limit. const int kReadBufferSize = 2 * kMaxPacketSize; -class SimpleQuicDispatcher : public QuicDispatcher { - public: - SimpleQuicDispatcher(const QuicConfig& config, - const QuicCryptoServerConfig* crypto_config, - const QuicVersionVector& supported_versions, - QuicConnectionHelperInterface* helper, - QuicAlarmFactory* alarm_factory) - : QuicDispatcher( - config, - crypto_config, - supported_versions, - std::unique_ptr<QuicConnectionHelperInterface>(helper), - std::unique_ptr<QuicServerSessionBase::Helper>( - new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), - std::unique_ptr<QuicAlarmFactory>(alarm_factory)) {} - - protected: - QuicServerSessionBase* CreateQuicSession( - QuicConnectionId connection_id, - const IPEndPoint& client_address) override { - QuicServerSessionBase* session = - QuicDispatcher::CreateQuicSession(connection_id, client_address); - static_cast<QuicSimplePerConnectionPacketWriter*>( - session->connection()->writer()) - ->set_connection(session->connection()); - return session; - } - - QuicPacketWriter* CreatePerConnectionWriter() override { - return new QuicSimplePerConnectionPacketWriter( - static_cast<QuicSimpleServerPacketWriter*>(writer())); - } -}; - } // namespace -QuicSimpleServer::QuicSimpleServer(ProofSource* proof_source, - const QuicConfig& config, - const QuicVersionVector& supported_versions) - : helper_( +QuicSimpleServer::QuicSimpleServer( + std::unique_ptr<ProofSource> proof_source, + const QuicConfig& config, + const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, + const QuicVersionVector& supported_versions) + : version_manager_(supported_versions), + helper_( new QuicChromiumConnectionHelper(&clock_, QuicRandom::GetInstance())), alarm_factory_(new QuicChromiumAlarmFactory( base::ThreadTaskRunnerHandle::Get().get(), &clock_)), config_(config), + crypto_config_options_(crypto_config_options), crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance(), - proof_source), - supported_versions_(supported_versions), + std::move(proof_source)), read_pending_(false), synchronous_read_count_(0), read_buffer_(new IOBufferWithSize(kReadBufferSize)), @@ -110,14 +81,14 @@ void QuicSimpleServer::Initialize() { std::unique_ptr<CryptoHandshakeMessage> scfg(crypto_config_.AddDefaultConfig( helper_->GetRandomGenerator(), helper_->GetClock(), - QuicCryptoServerConfig::ConfigOptions())); + crypto_config_options_)); } QuicSimpleServer::~QuicSimpleServer() {} int QuicSimpleServer::Listen(const IPEndPoint& address) { std::unique_ptr<UDPServerSocket> socket( - new UDPServerSocket(&net_log_, NetLog::Source())); + new UDPServerSocket(&net_log_, NetLogSource())); socket->AllowAddressReuse(); @@ -153,8 +124,12 @@ int QuicSimpleServer::Listen(const IPEndPoint& address) { socket_.swap(socket); - dispatcher_.reset(new SimpleQuicDispatcher( - config_, &crypto_config_, supported_versions_, helper_, alarm_factory_)); + dispatcher_.reset(new QuicSimpleDispatcher( + config_, &crypto_config_, &version_manager_, + std::unique_ptr<QuicConnectionHelperInterface>(helper_), + std::unique_ptr<QuicCryptoServerStream::Helper>( + new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), + std::unique_ptr<QuicAlarmFactory>(alarm_factory_))); QuicSimpleServerPacketWriter* writer = new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); dispatcher_->InitializeWithWriter(writer); @@ -174,6 +149,11 @@ void QuicSimpleServer::Shutdown() { } void QuicSimpleServer::StartReading() { + if (synchronous_read_count_ == 0) { + // Only process buffered packets once per message loop. + dispatcher_->ProcessBufferedChlos(kNumSessionsToCreatePerSocketEvent); + } + if (read_pending_) { return; } @@ -185,6 +165,12 @@ void QuicSimpleServer::StartReading() { if (result == ERR_IO_PENDING) { synchronous_read_count_ = 0; + if (dispatcher_->HasChlosBuffered()) { + // No more packets to read, so yield before processing buffered packets. + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&QuicSimpleServer::StartReading, + weak_factory_.GetWeakPtr())); + } return; } |