summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjdorfman <jdorfman@google.com>2016-01-04 09:41:29 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-04 17:42:12 +0000
commit5a606726430c9f3ddfd3084d04bff433b731bd52 (patch)
tree68482a330e529deef64103426e33d2e9331dcdab
parent30b29daf4337e410572df2b1d5389ac78398610c (diff)
downloadchromium_src-5a606726430c9f3ddfd3084d04bff433b731bd52.zip
chromium_src-5a606726430c9f3ddfd3084d04bff433b731bd52.tar.gz
chromium_src-5a606726430c9f3ddfd3084d04bff433b731bd52.tar.bz2
Refactor QUIC buffer allocation to support an injectable allocator. No functional change. Not flag protected.
Merging internal change: 111313822 Review URL: https://codereview.chromium.org/1551863005 Cr-Commit-Position: refs/heads/master@{#367321}
-rw-r--r--net/net.gypi3
-rw-r--r--net/quic/quic_connection.cc6
-rw-r--r--net/quic/quic_connection.h3
-rw-r--r--net/quic/quic_connection_helper.cc4
-rw-r--r--net/quic/quic_connection_helper.h3
-rw-r--r--net/quic/quic_connection_test.cc16
-rw-r--r--net/quic/quic_crypto_server_stream_test.cc8
-rw-r--r--net/quic/quic_packet_creator.cc5
-rw-r--r--net/quic/quic_packet_creator.h2
-rw-r--r--net/quic/quic_packet_creator_test.cc8
-rw-r--r--net/quic/quic_packet_generator.cc7
-rw-r--r--net/quic/quic_packet_generator.h1
-rw-r--r--net/quic/quic_packet_generator_test.cc4
-rw-r--r--net/quic/quic_protocol.cc14
-rw-r--r--net/quic/quic_protocol.h32
-rw-r--r--net/quic/quic_simple_buffer_allocator.cc17
-rw-r--r--net/quic/quic_simple_buffer_allocator.h20
-rw-r--r--net/quic/quic_simple_buffer_allocator_test.cc35
-rw-r--r--net/quic/test_tools/quic_test_utils.cc4
-rw-r--r--net/quic/test_tools/quic_test_utils.h3
-rw-r--r--net/tools/quic/quic_client.cc13
-rw-r--r--net/tools/quic/quic_client.h4
-rw-r--r--net/tools/quic/quic_client_base.cc2
-rw-r--r--net/tools/quic/quic_client_base.h6
-rw-r--r--net/tools/quic/quic_epoll_connection_helper.cc4
-rw-r--r--net/tools/quic/quic_epoll_connection_helper.h3
-rw-r--r--net/tools/quic/quic_simple_client.cc13
-rw-r--r--net/tools/quic/quic_simple_client.h3
28 files changed, 206 insertions, 37 deletions
diff --git a/net/net.gypi b/net/net.gypi
index 999d87d..2bb7137 100644
--- a/net/net.gypi
+++ b/net/net.gypi
@@ -383,6 +383,8 @@
'quic/quic_server_id.h',
'quic/quic_session.cc',
'quic/quic_session.h',
+ 'quic/quic_simple_buffer_allocator.cc',
+ 'quic/quic_simple_buffer_allocator.h',
'quic/quic_socket_address_coder.cc',
'quic/quic_socket_address_coder.h',
'quic/quic_stream_sequencer.cc',
@@ -1593,6 +1595,7 @@
'quic/quic_sent_packet_manager_test.cc',
'quic/quic_server_id_test.cc',
'quic/quic_session_test.cc',
+ 'quic/quic_simple_buffer_allocator_test.cc',
'quic/quic_socket_address_coder_test.cc',
'quic/quic_spdy_stream_test.cc',
'quic/quic_stream_factory_test.cc',
diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc
index 332918f..322a20b 100644
--- a/net/quic/quic_connection.cc
+++ b/net/quic/quic_connection.cc
@@ -295,7 +295,11 @@ QuicConnection::QuicConnection(QuicConnectionId connection_id,
mtu_discovery_alarm_(helper->CreateAlarm(new MtuDiscoveryAlarm(this))),
visitor_(nullptr),
debug_visitor_(nullptr),
- packet_generator_(connection_id_, &framer_, random_generator_, this),
+ packet_generator_(connection_id_,
+ &framer_,
+ random_generator_,
+ helper->GetBufferAllocator(),
+ this),
fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))),
idle_network_timeout_(QuicTime::Delta::Infinite()),
overall_connection_timeout_(QuicTime::Delta::Infinite()),
diff --git a/net/quic/quic_connection.h b/net/quic/quic_connection.h
index 6aee255..ac1b284 100644
--- a/net/quic/quic_connection.h
+++ b/net/quic/quic_connection.h
@@ -264,6 +264,9 @@ class NET_EXPORT_PRIVATE QuicConnectionHelperInterface {
// notify |delegate| when the alarm fires. Caller takes ownership
// of the new alarm, which will not yet be "set" to fire.
virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0;
+
+ // Returns a QuicBufferAllocator to be used for all stream frame buffers.
+ virtual QuicBufferAllocator* GetBufferAllocator() = 0;
};
class NET_EXPORT_PRIVATE QuicConnection
diff --git a/net/quic/quic_connection_helper.cc b/net/quic/quic_connection_helper.cc
index 0ec9ec2..9b3d4d7 100644
--- a/net/quic/quic_connection_helper.cc
+++ b/net/quic/quic_connection_helper.cc
@@ -113,4 +113,8 @@ QuicAlarm* QuicConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
return new QuicChromeAlarm(clock_, task_runner_, delegate);
}
+QuicBufferAllocator* QuicConnectionHelper::GetBufferAllocator() {
+ return &buffer_allocator_;
+}
+
} // namespace net
diff --git a/net/quic/quic_connection_helper.h b/net/quic/quic_connection_helper.h
index 9b53f58..83961aa 100644
--- a/net/quic/quic_connection_helper.h
+++ b/net/quic/quic_connection_helper.h
@@ -16,6 +16,7 @@
#include "base/memory/weak_ptr.h"
#include "net/base/ip_endpoint.h"
#include "net/quic/quic_protocol.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/quic_time.h"
#include "net/udp/datagram_client_socket.h"
@@ -40,11 +41,13 @@ class NET_EXPORT_PRIVATE QuicConnectionHelper
const QuicClock* GetClock() const override;
QuicRandom* GetRandomGenerator() override;
QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
+ QuicBufferAllocator* GetBufferAllocator() override;
private:
base::TaskRunner* task_runner_;
const QuicClock* clock_;
QuicRandom* random_generator_;
+ SimpleBufferAllocator buffer_allocator_;
base::WeakPtrFactory<QuicConnectionHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuicConnectionHelper);
diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc
index 499b6bf..dc0447a 100644
--- a/net/quic/quic_connection_test.cc
+++ b/net/quic/quic_connection_test.cc
@@ -18,6 +18,7 @@
#include "net/quic/crypto/quic_encrypter.h"
#include "net/quic/quic_flags.h"
#include "net/quic/quic_protocol.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/mock_clock.h"
#include "net/quic/test_tools/mock_random.h"
@@ -222,9 +223,14 @@ class TestConnectionHelper : public QuicConnectionHelperInterface {
return new TestAlarm(delegate);
}
+ QuicBufferAllocator* GetBufferAllocator() override {
+ return &buffer_allocator_;
+ }
+
private:
MockClock* clock_;
MockRandom* random_generator_;
+ SimpleBufferAllocator buffer_allocator_;
DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper);
};
@@ -665,13 +671,14 @@ class QuicConnectionTest : public ::testing::TestWithParam<TestParams> {
framer_(SupportedVersions(version()),
QuicTime::Zero(),
Perspective::IS_CLIENT),
+ send_algorithm_(new StrictMock<MockSendAlgorithm>),
+ loss_algorithm_(new MockLossAlgorithm()),
+ helper_(new TestConnectionHelper(&clock_, &random_generator_)),
peer_creator_(connection_id_,
&framer_,
&random_generator_,
+ &buffer_allocator_,
/*delegate=*/nullptr),
- send_algorithm_(new StrictMock<MockSendAlgorithm>),
- loss_algorithm_(new MockLossAlgorithm()),
- helper_(new TestConnectionHelper(&clock_, &random_generator_)),
writer_(new TestPacketWriter(version(), &clock_)),
factory_(writer_.get()),
connection_(connection_id_,
@@ -1087,14 +1094,15 @@ class QuicConnectionTest : public ::testing::TestWithParam<TestParams> {
QuicConnectionId connection_id_;
QuicFramer framer_;
- QuicPacketCreator peer_creator_;
MockEntropyCalculator entropy_calculator_;
MockSendAlgorithm* send_algorithm_;
MockLossAlgorithm* loss_algorithm_;
MockClock clock_;
MockRandom random_generator_;
+ SimpleBufferAllocator buffer_allocator_;
scoped_ptr<TestConnectionHelper> helper_;
+ QuicPacketCreator peer_creator_;
scoped_ptr<TestPacketWriter> writer_;
NiceMock<MockPacketWriterFactory> factory_;
TestConnection connection_;
diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc
index 055d408..bded756 100644
--- a/net/quic/quic_crypto_server_stream_test.cc
+++ b/net/quic/quic_crypto_server_stream_test.cc
@@ -94,7 +94,13 @@ class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> {
}
}
- ~QuicCryptoServerStreamTest() override { STLDeleteElements(&helpers_); }
+ ~QuicCryptoServerStreamTest() override {
+ // Ensure that anything that might reference |helpers_| is destroyed before
+ // |helpers_| is destroyed.
+ server_session_.reset();
+ client_session_.reset();
+ STLDeleteElements(&helpers_);
+ }
// Initializes the crypto server stream state for testing. May be
// called multiple times.
diff --git a/net/quic/quic_packet_creator.cc b/net/quic/quic_packet_creator.cc
index 7305fea..403bd01 100644
--- a/net/quic/quic_packet_creator.cc
+++ b/net/quic/quic_packet_creator.cc
@@ -82,6 +82,7 @@ class QuicRandomBoolSource {
QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id,
QuicFramer* framer,
QuicRandom* random_generator,
+ QuicBufferAllocator* buffer_allocator,
DelegateInterface* delegate)
: delegate_(delegate),
debug_delegate_(nullptr),
@@ -92,6 +93,7 @@ QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id,
framer_(framer),
random_bool_source_(new QuicRandomBoolSource(random_generator)),
current_path_(kDefaultPathId),
+ buffer_allocator_(buffer_allocator),
packet_number_(0),
should_fec_protect_next_packet_(false),
fec_protect_(false),
@@ -333,7 +335,8 @@ size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id,
size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size);
bool set_fin = fin && bytes_consumed == data_size; // Last frame.
- UniqueStreamBuffer buffer = NewStreamBuffer(bytes_consumed);
+ UniqueStreamBuffer buffer =
+ NewStreamBuffer(buffer_allocator_, bytes_consumed);
CopyToBuffer(iov, iov_offset, bytes_consumed, buffer.get());
*frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, bytes_consumed,
std::move(buffer)));
diff --git a/net/quic/quic_packet_creator.h b/net/quic/quic_packet_creator.h
index a70c1bb..ded7678 100644
--- a/net/quic/quic_packet_creator.h
+++ b/net/quic/quic_packet_creator.h
@@ -65,6 +65,7 @@ class NET_EXPORT_PRIVATE QuicPacketCreator {
QuicPacketCreator(QuicConnectionId connection_id,
QuicFramer* framer,
QuicRandom* random_generator,
+ QuicBufferAllocator* buffer_allocator,
DelegateInterface* delegate);
~QuicPacketCreator();
@@ -378,6 +379,7 @@ class NET_EXPORT_PRIVATE QuicPacketCreator {
hash_map<QuicPathId, QuicPacketNumber> multipath_packet_number_;
// The path which current constructed packet will be sent on.
QuicPathId current_path_;
+ QuicBufferAllocator* const buffer_allocator_;
QuicPacketNumber packet_number_;
// True when creator is requested to turn on FEC protection. False otherwise.
// There is a time difference between should_fec_protect_next_packet is
diff --git a/net/quic/quic_packet_creator_test.cc b/net/quic/quic_packet_creator_test.cc
index 3a97683..a8bc9f4 100644
--- a/net/quic/quic_packet_creator_test.cc
+++ b/net/quic/quic_packet_creator_test.cc
@@ -12,6 +12,7 @@
#include "net/quic/crypto/quic_decrypter.h"
#include "net/quic/crypto/quic_encrypter.h"
#include "net/quic/quic_flags.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/mock_random.h"
#include "net/quic/test_tools/quic_framer_peer.h"
@@ -119,7 +120,11 @@ class QuicPacketCreatorTest : public ::testing::TestWithParam<TestParams> {
Perspective::IS_CLIENT),
connection_id_(2),
data_("foo"),
- creator_(connection_id_, &client_framer_, &mock_random_, &delegate_),
+ creator_(connection_id_,
+ &client_framer_,
+ &mock_random_,
+ &buffer_allocator_,
+ &delegate_),
serialized_packet_(creator_.NoPacket()) {
creator_.set_connection_id_length(GetParam().connection_id_length);
@@ -197,6 +202,7 @@ class QuicPacketCreatorTest : public ::testing::TestWithParam<TestParams> {
string data_;
struct iovec iov_;
MockRandom mock_random_;
+ SimpleBufferAllocator buffer_allocator_;
QuicPacketCreator creator_;
MockEntropyCalculator entropy_calculator_;
SerializedPacket serialized_packet_;
diff --git a/net/quic/quic_packet_generator.cc b/net/quic/quic_packet_generator.cc
index df04dc7..0ca3d50 100644
--- a/net/quic/quic_packet_generator.cc
+++ b/net/quic/quic_packet_generator.cc
@@ -18,9 +18,14 @@ class QuicAckNotifier;
QuicPacketGenerator::QuicPacketGenerator(QuicConnectionId connection_id,
QuicFramer* framer,
QuicRandom* random_generator,
+ QuicBufferAllocator* buffer_allocator,
DelegateInterface* delegate)
: delegate_(delegate),
- packet_creator_(connection_id, framer, random_generator, delegate),
+ packet_creator_(connection_id,
+ framer,
+ random_generator,
+ buffer_allocator,
+ delegate),
batch_mode_(false),
should_send_ack_(false),
should_send_stop_waiting_(false),
diff --git a/net/quic/quic_packet_generator.h b/net/quic/quic_packet_generator.h
index e9e56c3..8f3182d 100644
--- a/net/quic/quic_packet_generator.h
+++ b/net/quic/quic_packet_generator.h
@@ -86,6 +86,7 @@ class NET_EXPORT_PRIVATE QuicPacketGenerator {
QuicPacketGenerator(QuicConnectionId connection_id,
QuicFramer* framer,
QuicRandom* random_generator,
+ QuicBufferAllocator* buffer_allocator,
DelegateInterface* delegate);
~QuicPacketGenerator();
diff --git a/net/quic/quic_packet_generator_test.cc b/net/quic/quic_packet_generator_test.cc
index 458df68..44f909a 100644
--- a/net/quic/quic_packet_generator_test.cc
+++ b/net/quic/quic_packet_generator_test.cc
@@ -12,6 +12,7 @@
#include "net/quic/crypto/quic_decrypter.h"
#include "net/quic/crypto/quic_encrypter.h"
#include "net/quic/quic_flags.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/quic_packet_creator_peer.h"
#include "net/quic/test_tools/quic_packet_generator_peer.h"
@@ -113,7 +114,7 @@ class QuicPacketGeneratorTest : public ::testing::TestWithParam<FecSendPolicy> {
: framer_(QuicSupportedVersions(),
QuicTime::Zero(),
Perspective::IS_CLIENT),
- generator_(42, &framer_, &random_, &delegate_),
+ generator_(42, &framer_, &random_, &buffer_allocator_, &delegate_),
creator_(QuicPacketGeneratorPeer::GetPacketCreator(&generator_)) {
generator_.set_fec_send_policy(GetParam());
}
@@ -222,6 +223,7 @@ class QuicPacketGeneratorTest : public ::testing::TestWithParam<FecSendPolicy> {
QuicFramer framer_;
MockRandom random_;
+ SimpleBufferAllocator buffer_allocator_;
StrictMock<MockDelegate> delegate_;
QuicPacketGenerator generator_;
QuicPacketCreator* creator_;
diff --git a/net/quic/quic_protocol.cc b/net/quic/quic_protocol.cc
index 9b56555..7626f0b 100644
--- a/net/quic/quic_protocol.cc
+++ b/net/quic/quic_protocol.cc
@@ -101,12 +101,18 @@ QuicPublicResetPacket::QuicPublicResetPacket(
const QuicPacketPublicHeader& header)
: public_header(header), nonce_proof(0), rejected_packet_number(0) {}
-void StreamBufferDeleter::operator()(char* buf) const {
- delete[] buf;
+QuicBufferAllocator::~QuicBufferAllocator() = default;
+
+void StreamBufferDeleter::operator()(char* buffer) const {
+ if (allocator_ != nullptr && buffer != nullptr) {
+ allocator_->Delete(buffer);
+ }
}
-UniqueStreamBuffer NewStreamBuffer(size_t size) {
- return UniqueStreamBuffer(new char[size]);
+UniqueStreamBuffer NewStreamBuffer(QuicBufferAllocator* allocator,
+ size_t size) {
+ return UniqueStreamBuffer(allocator->New(size),
+ StreamBufferDeleter(allocator));
}
QuicStreamFrame::QuicStreamFrame()
diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h
index 2bf7146..aee3543 100644
--- a/net/quic/quic_protocol.h
+++ b/net/quic/quic_protocol.h
@@ -715,16 +715,40 @@ struct NET_EXPORT_PRIVATE QuicPingFrame {};
// frame.
struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
-// Deleter for stream buffers.
+class NET_EXPORT_PRIVATE QuicBufferAllocator {
+ public:
+ virtual ~QuicBufferAllocator();
+
+ // Returns or allocates a new buffer of |size|. Never returns null.
+ virtual char* New(size_t size) = 0;
+
+ // Releases a buffer.
+ virtual void Delete(char* buffer) = 0;
+};
+
+// Deleter for stream buffers. Copyable to support platforms where the deleter
+// of a unique_ptr must be copyable. Otherwise it would be nice for this to be
+// move-only.
class NET_EXPORT_PRIVATE StreamBufferDeleter {
public:
- void operator()(char* buf) const;
+ StreamBufferDeleter() : allocator_(nullptr) {}
+ explicit StreamBufferDeleter(QuicBufferAllocator* allocator)
+ : allocator_(allocator) {}
+
+ // Deletes |buffer| using |allocator_|.
+ void operator()(char* buffer) const;
+
+ private:
+ // Not owned; must be valid so long as the buffer stored in the unique_ptr
+ // that owns |this| is valid.
+ QuicBufferAllocator* allocator_;
};
using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>;
-// Allocates memory of size |size| for a QUIC stream buffer.
-UniqueStreamBuffer NewStreamBuffer(size_t size);
+// Allocates memory of size |size| using |allocator| for a QUIC stream buffer.
+NET_EXPORT_PRIVATE UniqueStreamBuffer
+NewStreamBuffer(QuicBufferAllocator* allocator, size_t size);
struct NET_EXPORT_PRIVATE QuicStreamFrame {
QuicStreamFrame();
diff --git a/net/quic/quic_simple_buffer_allocator.cc b/net/quic/quic_simple_buffer_allocator.cc
new file mode 100644
index 0000000..5dae280
--- /dev/null
+++ b/net/quic/quic_simple_buffer_allocator.cc
@@ -0,0 +1,17 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/quic_simple_buffer_allocator.h"
+
+namespace net {
+
+char* SimpleBufferAllocator::New(size_t size) {
+ return new char[size];
+}
+
+void SimpleBufferAllocator::Delete(char* buffer) {
+ delete[] buffer;
+}
+
+} // namespace net
diff --git a/net/quic/quic_simple_buffer_allocator.h b/net/quic/quic_simple_buffer_allocator.h
new file mode 100644
index 0000000..171f6b0
--- /dev/null
+++ b/net/quic/quic_simple_buffer_allocator.h
@@ -0,0 +1,20 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_SIMPLE_BUFFER_ALLOCATOR_H_
+#define NET_QUIC_SIMPLE_BUFFER_ALLOCATOR_H_
+
+#include "net/quic/quic_protocol.h"
+
+namespace net {
+
+class NET_EXPORT_PRIVATE SimpleBufferAllocator : public QuicBufferAllocator {
+ public:
+ char* New(size_t size) override;
+ void Delete(char* buffer) override;
+};
+
+} // namespace net
+
+#endif // NET_QUIC_SIMPLE_BUFFER_ALLOCATOR_H_
diff --git a/net/quic/quic_simple_buffer_allocator_test.cc b/net/quic/quic_simple_buffer_allocator_test.cc
new file mode 100644
index 0000000..3129b96
--- /dev/null
+++ b/net/quic/quic_simple_buffer_allocator_test.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/quic_simple_buffer_allocator.h"
+
+#include "net/quic/quic_protocol.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::Eq;
+
+namespace net {
+namespace {
+
+TEST(SimpleBufferAllocatorTest, NewDelete) {
+ SimpleBufferAllocator alloc;
+ char* buf = alloc.New(4);
+ EXPECT_NE(nullptr, buf);
+ alloc.Delete(buf);
+}
+
+TEST(SimpleBufferAllocatorTest, DeleteNull) {
+ SimpleBufferAllocator alloc;
+ alloc.Delete(nullptr);
+}
+
+TEST(SimpleBufferAllocatorTest, StoreInUniqueStreamBuffer) {
+ SimpleBufferAllocator alloc;
+ UniqueStreamBuffer buf = NewStreamBuffer(&alloc, 4);
+ buf.reset();
+}
+
+} // namespace
+} // namespace net
diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc
index ba2bb61..033ea75 100644
--- a/net/quic/test_tools/quic_test_utils.cc
+++ b/net/quic/test_tools/quic_test_utils.cc
@@ -209,6 +209,10 @@ QuicAlarm* MockConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
return new TestAlarm(delegate);
}
+QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() {
+ return &buffer_allocator_;
+}
+
void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) {
clock_.AdvanceTime(delta);
}
diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h
index d4db512..44cfa2e 100644
--- a/net/quic/test_tools/quic_test_utils.h
+++ b/net/quic/test_tools/quic_test_utils.h
@@ -23,6 +23,7 @@
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_sent_packet_manager.h"
#include "net/quic/quic_session.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/test_tools/mock_clock.h"
#include "net/quic/test_tools/mock_random.h"
#include "net/spdy/spdy_framer.h"
@@ -301,11 +302,13 @@ class MockConnectionHelper : public QuicConnectionHelperInterface {
const QuicClock* GetClock() const override;
QuicRandom* GetRandomGenerator() override;
QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
+ QuicBufferAllocator* GetBufferAllocator() override;
void AdvanceTime(QuicTime::Delta delta);
private:
MockClock clock_;
MockRandom random_generator_;
+ SimpleBufferAllocator buffer_allocator_;
DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper);
};
diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc
index 33b3e96..b1ed67e 100644
--- a/net/tools/quic/quic_client.cc
+++ b/net/tools/quic/quic_client.cc
@@ -60,12 +60,15 @@ QuicClient::QuicClient(IPEndPoint server_address,
const QuicConfig& config,
EpollServer* epoll_server,
ProofVerifier* proof_verifier)
- : QuicClientBase(server_id, supported_versions, config, proof_verifier),
+ : QuicClientBase(server_id,
+ supported_versions,
+ config,
+ new QuicEpollConnectionHelper(epoll_server),
+ proof_verifier),
server_address_(server_address),
local_port_(0),
epoll_server_(epoll_server),
fd_(-1),
- helper_(CreateQuicConnectionHelper()),
initialized_(false),
packets_dropped_(0),
overflow_supported_(false),
@@ -245,7 +248,7 @@ void QuicClient::StartConnect() {
}
CreateQuicClientSession(new QuicConnection(
- GetNextConnectionId(), server_address_, helper_.get(), factory,
+ GetNextConnectionId(), server_address_, helper(), factory,
/* owns_writer= */ false, Perspective::IS_CLIENT, supported_versions()));
// Reset |writer_| after |session()| so that the old writer outlives the old
@@ -438,10 +441,6 @@ const string& QuicClient::latest_response_trailers() const {
return latest_response_trailers_;
}
-QuicEpollConnectionHelper* QuicClient::CreateQuicConnectionHelper() {
- return new QuicEpollConnectionHelper(epoll_server_);
-}
-
QuicPacketWriter* QuicClient::CreateQuicPacketWriter() {
return new QuicDefaultPacketWriter(fd_);
}
diff --git a/net/tools/quic/quic_client.h b/net/tools/quic/quic_client.h
index cb06c7f..29febd7 100644
--- a/net/tools/quic/quic_client.h
+++ b/net/tools/quic/quic_client.h
@@ -170,7 +170,6 @@ class QuicClient : public QuicClientBase,
const std::string& latest_response_trailers() const;
protected:
- virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper();
virtual QuicPacketWriter* CreateQuicPacketWriter();
virtual int ReadPacket(char* buffer,
@@ -235,9 +234,6 @@ class QuicClient : public QuicClientBase,
// UDP socket.
int fd_;
- // Helper to be used by created connections.
- scoped_ptr<QuicEpollConnectionHelper> helper_;
-
// Listens for full responses.
scoped_ptr<ResponseListener> response_listener_;
diff --git a/net/tools/quic/quic_client_base.cc b/net/tools/quic/quic_client_base.cc
index 0364998..2c985c2 100644
--- a/net/tools/quic/quic_client_base.cc
+++ b/net/tools/quic/quic_client_base.cc
@@ -13,10 +13,12 @@ namespace tools {
QuicClientBase::QuicClientBase(const QuicServerId& server_id,
const QuicVersionVector& supported_versions,
const QuicConfig& config,
+ QuicConnectionHelperInterface* helper,
ProofVerifier* proof_verifier)
: server_id_(server_id),
config_(config),
crypto_config_(proof_verifier),
+ helper_(helper),
supported_versions_(supported_versions),
initial_max_packet_length_(0),
num_stateless_rejects_received_(0),
diff --git a/net/tools/quic/quic_client_base.h b/net/tools/quic/quic_client_base.h
index 046276a..449cc85 100644
--- a/net/tools/quic/quic_client_base.h
+++ b/net/tools/quic/quic_client_base.h
@@ -48,6 +48,7 @@ class QuicClientBase {
QuicClientBase(const QuicServerId& server_id,
const QuicVersionVector& supported_versions,
const QuicConfig& config,
+ QuicConnectionHelperInterface* helper,
ProofVerifier* proof_verifier);
~QuicClientBase();
@@ -180,6 +181,8 @@ class QuicClientBase {
// connection ID).
virtual QuicConnectionId GenerateNewConnectionId();
+ QuicConnectionHelperInterface* helper() { return helper_.get(); }
+
private:
// |server_id_| is a tuple (hostname, port, is_https) of the server.
QuicServerId server_id_;
@@ -189,6 +192,9 @@ class QuicClientBase {
QuicConfig config_;
QuicCryptoClientConfig crypto_config_;
+ // Helper to be used by created connections. Needs to outlive |session_|.
+ scoped_ptr<QuicConnectionHelperInterface> helper_;
+
// Writer used to actually send packets to the wire. Needs to outlive
// |session_|.
scoped_ptr<QuicPacketWriter> writer_;
diff --git a/net/tools/quic/quic_epoll_connection_helper.cc b/net/tools/quic/quic_epoll_connection_helper.cc
index df7f762..853f0d0 100644
--- a/net/tools/quic/quic_epoll_connection_helper.cc
+++ b/net/tools/quic/quic_epoll_connection_helper.cc
@@ -81,5 +81,9 @@ QuicAlarm* QuicEpollConnectionHelper::CreateAlarm(
return new QuicEpollAlarm(epoll_server_, delegate);
}
+QuicBufferAllocator* QuicEpollConnectionHelper::GetBufferAllocator() {
+ return &buffer_allocator_;
+}
+
} // namespace tools
} // namespace net
diff --git a/net/tools/quic/quic_epoll_connection_helper.h b/net/tools/quic/quic_epoll_connection_helper.h
index cc99b60..b3cc28e 100644
--- a/net/tools/quic/quic_epoll_connection_helper.h
+++ b/net/tools/quic/quic_epoll_connection_helper.h
@@ -15,6 +15,7 @@
#include "net/quic/quic_connection.h"
#include "net/quic/quic_packet_writer.h"
#include "net/quic/quic_protocol.h"
+#include "net/quic/quic_simple_buffer_allocator.h"
#include "net/quic/quic_time.h"
#include "net/tools/quic/quic_default_packet_writer.h"
#include "net/tools/quic/quic_epoll_clock.h"
@@ -40,6 +41,7 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
const QuicClock* GetClock() const override;
QuicRandom* GetRandomGenerator() override;
QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
+ QuicBufferAllocator* GetBufferAllocator() override;
EpollServer* epoll_server() { return epoll_server_; }
@@ -50,6 +52,7 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
const QuicEpollClock clock_;
QuicRandom* random_generator_;
+ SimpleBufferAllocator buffer_allocator_;
DISALLOW_COPY_AND_ASSIGN(QuicEpollConnectionHelper);
};
diff --git a/net/tools/quic/quic_simple_client.cc b/net/tools/quic/quic_simple_client.cc
index 3a268efe..d7a3004 100644
--- a/net/tools/quic/quic_simple_client.cc
+++ b/net/tools/quic/quic_simple_client.cc
@@ -42,10 +42,10 @@ QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
: QuicClientBase(server_id,
supported_versions,
QuicConfig(),
+ CreateQuicConnectionHelper(),
proof_verifier),
server_address_(server_address),
local_port_(0),
- helper_(CreateQuicConnectionHelper()),
initialized_(false),
packet_reader_started_(false),
weak_factory_(this) {}
@@ -55,10 +55,13 @@ QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
const QuicVersionVector& supported_versions,
const QuicConfig& config,
ProofVerifier* proof_verifier)
- : QuicClientBase(server_id, supported_versions, config, proof_verifier),
+ : QuicClientBase(server_id,
+ supported_versions,
+ config,
+ CreateQuicConnectionHelper(),
+ proof_verifier),
server_address_(server_address),
local_port_(0),
- helper_(CreateQuicConnectionHelper()),
initialized_(false),
packet_reader_started_(false),
weak_factory_(this) {}
@@ -217,7 +220,7 @@ void QuicSimpleClient::StartConnect() {
}
CreateQuicClientSession(new QuicConnection(
- GetNextConnectionId(), server_address_, helper_.get(), factory,
+ GetNextConnectionId(), server_address_, helper(), factory,
/* owns_writer= */ false, Perspective::IS_CLIENT, supported_versions()));
session()->Initialize();
@@ -373,7 +376,7 @@ const string& QuicSimpleClient::latest_response_body() const {
}
QuicConnectionId QuicSimpleClient::GenerateNewConnectionId() {
- return helper_->GetRandomGenerator()->RandUint64();
+ return helper()->GetRandomGenerator()->RandUint64();
}
QuicConnectionHelper* QuicSimpleClient::CreateQuicConnectionHelper() {
diff --git a/net/tools/quic/quic_simple_client.h b/net/tools/quic/quic_simple_client.h
index d629234..4f3454a 100644
--- a/net/tools/quic/quic_simple_client.h
+++ b/net/tools/quic/quic_simple_client.h
@@ -221,9 +221,6 @@ class QuicSimpleClient : public QuicClientBase,
// UDP socket connected to the server.
scoped_ptr<UDPClientSocket> socket_;
- // Helper to be used by created connections.
- scoped_ptr<QuicConnectionHelper> helper_;
-
// Listens for full responses.
scoped_ptr<ResponseListener> response_listener_;