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

Unified Diff: net/socket/ssl_client_socket_impl.cc

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Fix tests for real Created 3 years, 11 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/ssl_client_socket_impl.cc
diff --git a/net/socket/ssl_client_socket_impl.cc b/net/socket/ssl_client_socket_impl.cc
index c993fa8fb23da2d1d58c35731b3801a19283ff11..4e6924446494db2503173078443a1ac0a859f3ea 100644
--- a/net/socket/ssl_client_socket_impl.cc
+++ b/net/socket/ssl_client_socket_impl.cc
@@ -877,6 +877,16 @@ int SSLClientSocketImpl::Read(IOBuffer* buf,
return rv;
}
+int SSLClientSocketImpl::ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) {
+ // Reuse Read() but do not hold on to |buf| and |buf_len|.
+ int rv = Read(buf, buf_len, callback);
+ user_read_buf_ = nullptr;
+ user_read_buf_len_ = 0;
davidben 2017/02/01 22:25:57 Hrm. Rather than let Read() set up some state and
xunjieli 2017/02/03 16:35:33 Done.
+ return rv;
+}
+
int SSLClientSocketImpl::Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) {
@@ -905,15 +915,24 @@ int SSLClientSocketImpl::SetSendBufferSize(int32_t size) {
return transport_->socket()->SetSendBufferSize(size);
}
-void SSLClientSocketImpl::OnReadReady() {
+void SSLClientSocketImpl::OnReadReady(int rv) {
+ // If ReadIfReady() is called instead of Read().
davidben 2017/02/01 22:25:57 This logic might be better in RetryAllOperations()
xunjieli 2017/02/03 16:35:33 Done. Ah, there's a third case! Should have done a
+ if (!user_read_callback_.is_null() && user_read_buf_ == nullptr) {
+ base::ResetAndReturn(&user_read_callback_).Run(rv);
+ return;
davidben 2017/02/01 22:25:57 This return means we won't wake up other operation
xunjieli 2017/02/03 16:35:33 Acknowledged.
+ }
// During a renegotiation, either Read or Write calls may be blocked on a
// transport read.
RetryAllOperations();
}
-void SSLClientSocketImpl::OnWriteReady() {
+void SSLClientSocketImpl::OnWriteReady(int rv) {
// During a renegotiation, either Read or Write calls may be blocked on a
// transport read.
+ if (!user_read_callback_.is_null() && user_read_buf_ == nullptr) {
+ base::ResetAndReturn(&user_read_callback_).Run(rv);
+ return;
+ }
RetryAllOperations();
}

Powered by Google App Engine
This is Rietveld 408576698