Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Unified Diff: net/socket/socket_test_util.h

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/socket_posix.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/socket_test_util.h
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index c8f9b68fe9f8e33953d8b42ee28dc689ae84db9a..9790f498fa7bf067c43b6bde2f1f2927518b18d4 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -518,6 +518,10 @@ class MockClientSocketFactory : public ClientSocketFactory {
return mock_data_;
}
+ void set_enable_read_if_ready(bool enable_read_if_ready) {
+ enable_read_if_ready_ = enable_read_if_ready;
+ }
+
// ClientSocketFactory
std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
DatagramSocket::BindType bind_type,
@@ -545,6 +549,10 @@ class MockClientSocketFactory : public ClientSocketFactory {
SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
std::vector<uint16_t> udp_client_socket_ports_;
+ // If true, ReadIfReady() is enabled; otherwise ReadIfReady() returns
+ // ERR_READ_IF_READY_NOT_IMPLEMENTED.
+ bool enable_read_if_ready_;
+
DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory);
};
@@ -627,6 +635,9 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
+ int ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) override;
int Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
@@ -650,9 +661,15 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
void OnConnectComplete(const MockConnect& data) override;
void OnDataProviderDestroyed() override;
- private:
- int CompleteRead();
+ void set_enable_read_if_ready(bool enable_read_if_ready) {
+ enable_read_if_ready_ = enable_read_if_ready;
+ }
+ private:
+ void RetryRead(int rv);
+ int ReadIfReadyImpl(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
AddressList addresses_;
SocketDataProvider* data_;
@@ -668,11 +685,19 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
// While an asynchronous read is pending, we save our user-buffer state.
scoped_refptr<IOBuffer> pending_read_buf_;
int pending_read_buf_len_;
- CompletionCallback pending_connect_callback_;
CompletionCallback pending_read_callback_;
+
+ // Non-null when a ReadIfReady() is pending.
+ CompletionCallback pending_read_if_ready_callback_;
+
+ CompletionCallback pending_connect_callback_;
CompletionCallback pending_write_callback_;
bool was_used_to_convey_data_;
+ // If true, ReadIfReady() is enabled; otherwise ReadIfReady() returns
+ // ERR_READ_IF_READY_NOT_IMPLEMENTED.
+ bool enable_read_if_ready_;
+
ConnectionAttempts connection_attempts_;
DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocket);
@@ -690,6 +715,9 @@ class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
+ int ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) override;
int Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
« no previous file with comments | « net/socket/socket_posix.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698