summaryrefslogtreecommitdiffstats
path: root/net/socket/socket_test_util.h
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-11 22:04:22 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-11 22:04:22 +0000
commit584460dac4ee02b146000be533fb4cc8cb2ab108 (patch)
tree1d13471bf7add3ff4d0bd1f6be678b31bdfa746a /net/socket/socket_test_util.h
parent0e5a729239c4be751a5c582249b943243c5b3e60 (diff)
downloadchromium_src-584460dac4ee02b146000be533fb4cc8cb2ab108.zip
chromium_src-584460dac4ee02b146000be533fb4cc8cb2ab108.tar.gz
chromium_src-584460dac4ee02b146000be533fb4cc8cb2ab108.tar.bz2
Enable async IO completions on MockSockets through the
SocketDataProvider. This makes a few changes: - The SocketDataProvider::GetNextRead() is now allowed to return a result of ERR_IO_PENDING. Previously, this was just an error. Now, this informs the MockClientSocket using the SocketDataProvider that the Mock IO will be completely asynchronously. - MockClientSocket implements a new method called OnReadComplete(). This method is used to asynchronously complete a Read from the SocketDataProvider. The MockClientSocket, after receiving ERR_IO_PENDING from SocketDataProvider::GetNextRead will be blocked until this call is made. The rest of the patch is just refactoring the MockTCPClientSocket to implement a true async-io simulation. It needs to record the user buffer from the initial read, and then fill it when the data is provided. BUG=none TEST=<this is for better testing> Review URL: http://codereview.chromium.org/392003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socket_test_util.h')
-rw-r--r--net/socket/socket_test_util.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 0e1380c..c369435 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -27,6 +27,7 @@ namespace net {
class ClientSocket;
class LoadLog;
+class MockClientSocket;
class SSLClientSocket;
struct MockConnect {
@@ -78,17 +79,27 @@ struct MockWriteResult {
// for getting data about individual reads and writes on the socket.
class SocketDataProvider {
public:
- SocketDataProvider() {}
+ SocketDataProvider() : socket_(NULL) {}
virtual ~SocketDataProvider() {}
+
+ // Returns the buffer and result code for the next simulated read.
+ // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller
+ // that it will be called via the MockClientSocket::OnReadComplete()
+ // function at a later time.
virtual MockRead GetNextRead() = 0;
virtual MockWriteResult OnWrite(const std::string& data) = 0;
virtual void Reset() = 0;
+ // Accessor for the socket which is using the SocketDataProvider.
+ MockClientSocket* socket() { return socket_; }
+ void set_socket(MockClientSocket* socket) { socket_ = socket; }
+
MockConnect connect_data() const { return connect_; }
private:
MockConnect connect_;
+ MockClientSocket* socket_;
DISALLOW_COPY_AND_ASSIGN(SocketDataProvider);
};
@@ -264,6 +275,11 @@ class MockClientSocket : public net::SSLClientSocket {
virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen);
#endif
+ // If an async IO is pending because the SocketDataProvider returned
+ // ERR_IO_PENDING, then the MockClientSocket waits until this OnReadComplete
+ // is called to complete the asynchronous read operation.
+ virtual void OnReadComplete(const MockRead& data) = 0;
+
protected:
void RunCallbackAsync(net::CompletionCallback* callback, int result);
void RunCallback(net::CompletionCallback*, int result);
@@ -287,15 +303,24 @@ class MockTCPClientSocket : public MockClientSocket {
virtual int Write(net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback);
+ virtual void OnReadComplete(const MockRead& data);
+
net::AddressList addresses() const { return addresses_; }
private:
+ int CompleteRead();
+
net::AddressList addresses_;
net::SocketDataProvider* data_;
int read_offset_;
net::MockRead read_data_;
bool need_read_data_;
+
+ // While an asynchronous IO is pending, we save our user-buffer state.
+ net::IOBuffer* pending_buf_;
+ int pending_buf_len_;
+ net::CompletionCallback* pending_callback_;
};
class MockSSLClientSocket : public MockClientSocket {
@@ -318,6 +343,9 @@ class MockSSLClientSocket : public MockClientSocket {
virtual int Write(net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback);
+ // This MockSocket does not implement the manual async IO feature.
+ virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); }
+
private:
class ConnectCallback;