diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 05:11:41 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 05:11:41 +0000 |
commit | d67d10528eb68753d19db1698b3688fa48fa44b3 (patch) | |
tree | 3797e452b5c689ff8da97dc9a73b775c610b07ea /net/base/test_data_stream.cc | |
parent | 785db4fe43f9b4b3ce1231dec4d723e379ed992b (diff) | |
download | chromium_src-d67d10528eb68753d19db1698b3688fa48fa44b3.zip chromium_src-d67d10528eb68753d19db1698b3688fa48fa44b3.tar.gz chromium_src-d67d10528eb68753d19db1698b3688fa48fa44b3.tar.bz2 |
Collect stats to investigate the viability of UDP
connectivity from the browser (first cut). Collect
stats for TCP connectivity also.
- What percentage of users can get a message end-to-end
to an TCP and UDP server.
- What is the latency for TCP and UDP messages.
Added TCP and UDP echo servers to testserver.py
for unittests.
BUG=82565
TEST=udp tests
Review URL: http://codereview.chromium.org/7056031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88495 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/test_data_stream.cc')
-rw-r--r-- | net/base/test_data_stream.cc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/net/base/test_data_stream.cc b/net/base/test_data_stream.cc new file mode 100644 index 0000000..6672804 --- /dev/null +++ b/net/base/test_data_stream.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2011 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/base/test_data_stream.h" + +namespace net { + +TestDataStream::TestDataStream() { + Reset(); +} + +// Fill |buffer| with |length| bytes of data from the stream. +void TestDataStream::GetBytes(char* buffer, int length) { + while (length) { + AdvanceIndex(); + int bytes_to_copy = std::min(length, bytes_remaining_); + memcpy(buffer, buffer_ptr_, bytes_to_copy); + buffer += bytes_to_copy; + Consume(bytes_to_copy); + length -= bytes_to_copy; + } +} + +bool TestDataStream::VerifyBytes(const char *buffer, int length) { + while (length) { + AdvanceIndex(); + int bytes_to_compare = std::min(length, bytes_remaining_); + if (memcmp(buffer, buffer_ptr_, bytes_to_compare)) + return false; + Consume(bytes_to_compare); + length -= bytes_to_compare; + buffer += bytes_to_compare; + } + return true; +} + +void TestDataStream::Reset() { + index_ = 0; + bytes_remaining_ = 0; + buffer_ptr_ = buffer_; +} + +// If there is no data spilled over from the previous index, advance the +// index and fill the buffer. +void TestDataStream::AdvanceIndex() { + if (bytes_remaining_ == 0) { + // Convert it to ascii, but don't bother to reverse it. + // (e.g. 12345 becomes "54321") + int val = index_++; + do { + buffer_[bytes_remaining_++] = (val % 10) + '0'; + } while ((val /= 10) > 0); + buffer_[bytes_remaining_++] = '.'; + } +} + +// Consume data from the spill buffer. +void TestDataStream::Consume(int bytes) { + bytes_remaining_ -= bytes; + if (bytes_remaining_) + buffer_ptr_ += bytes; + else + buffer_ptr_ = buffer_; +} + +} // namespace net + |