diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 10:36:56 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 10:36:56 +0000 |
commit | b690e18ca906d699e05cddae14250ab40439fee3 (patch) | |
tree | d34539a899c988f422f1235c7b52c2d1eb81d7ba /net/curvecp/test_client.h | |
parent | 51c0220843bfc1939d2f1525f0fc0192b4926369 (diff) | |
download | chromium_src-b690e18ca906d699e05cddae14250ab40439fee3.zip chromium_src-b690e18ca906d699e05cddae14250ab40439fee3.tar.gz chromium_src-b690e18ca906d699e05cddae14250ab40439fee3.tar.bz2 |
An initial curvecp implementation. This implementation is not complete,
but is good enough to start collaboration.
BUG=none
TEST=curvecp_unittests
Review URL: http://codereview.chromium.org/7037022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/curvecp/test_client.h')
-rw-r--r-- | net/curvecp/test_client.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/net/curvecp/test_client.h b/net/curvecp/test_client.h new file mode 100644 index 0000000..08f496f --- /dev/null +++ b/net/curvecp/test_client.h @@ -0,0 +1,70 @@ +// 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. + +#ifndef NET_CURVECP_TEST_CLIENT_H_ +#define NET_CURVECP_TEST_CLIENT_H_ +#pragma once + +#include "base/task.h" +#include "net/base/completion_callback.h" +#include "net/base/host_port_pair.h" +#include "net/base/io_buffer.h" +#include "net/curvecp/test_data_stream.h" + +namespace net { + +class CurveCPClientSocket; + +// The TestClient connects to a test server, sending a stream of verifiable +// bytes. The TestClient expects to get the same bytes echoed back from the +// TestServer. After sending all bytes and receiving the echoes, the +// TestClient closes itself. +// +// Several hooks are provided for testing edge cases and failures. +class TestClient { + public: + TestClient(); + virtual ~TestClient(); + + // Starts the client, connecting to |server|. + // Client will send |bytes_to_send| bytes from the verifiable stream. + // When the client has received all echoed bytes from the server, or + // when an error occurs causing the client to stop, |callback| will be + // called with a net status code. + // Returns true if successful in starting the client. + bool Start(const HostPortPair& server, + int bytes_to_send, + CompletionCallback* callback); + + // Returns the number of errors this server encountered. + int error_count() { return errors_; } + + private: + static const int kMaxMessage = 1024; + + void OnConnectComplete(int result); + void OnReadComplete(int result); + void OnWriteComplete(int result); + + void ReadData(); + void SendData(); + void Finish(int result); + + CurveCPClientSocket* socket_; + scoped_refptr<IOBuffer> read_buffer_; + scoped_refptr<DrainableIOBuffer> write_buffer_; + int errors_; + int bytes_to_read_; + int bytes_to_send_; + TestDataStream sent_stream_; + TestDataStream received_stream_; + CompletionCallbackImpl<TestClient> connect_callback_; + CompletionCallbackImpl<TestClient> read_callback_; + CompletionCallbackImpl<TestClient> write_callback_; + CompletionCallback* finished_callback_; +}; + +} // namespace net + +#endif // NET_CURVECP_TEST_CLIENT_H_ |