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

Unified Diff: net/socket/socket_test_util.h

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Self Created 3 years, 10 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
Index: net/socket/socket_test_util.h
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index fec7819d0e95661ad6a8e223b9d10862aeba73a7..ff15849a690e45c9525c88684811c0e81d578de6 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -518,6 +518,11 @@ class MockClientSocketFactory : public ClientSocketFactory {
return mock_data_;
}
+ // If |enable_read_if_ready|, ReadIfReady() will be implemented.
+ 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 +550,7 @@ class MockClientSocketFactory : public ClientSocketFactory {
SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
std::vector<uint16_t> udp_client_socket_ports_;
+ bool enable_read_if_ready_;
DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory);
};
@@ -627,6 +633,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,8 +659,17 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
void OnConnectComplete(const MockConnect& data) override;
void OnDataProviderDestroyed() override;
+ // If |enable_read_if_ready|, ReadIfReady() will be implemented.
+ void set_enable_read_if_ready(bool enable_read_if_ready) {
+ enable_read_if_ready_ = enable_read_if_ready;
+ }
+
private:
- int CompleteRead();
+ void RetryRead(int rv);
+ int ReadIfReadyHelper(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
+ void RunReadIfReadyCallback(int result);
AddressList addresses_;
@@ -668,13 +686,20 @@ 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_;
+ bool enable_read_if_ready_;
ConnectionAttempts connection_attempts_;
+ base::WeakPtrFactory<MockTCPClientSocket> weak_factory_;
+
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;

Powered by Google App Engine
This is Rietveld 408576698