Index: net/socket/socket_bio_adapter.cc |
diff --git a/net/socket/socket_bio_adapter.cc b/net/socket/socket_bio_adapter.cc |
index 0d75e68ec85890a2def5983dfdb1a4332a8d81e3..25b43261c0c732c17b1a782581377fc85303fa09 100644 |
--- a/net/socket/socket_bio_adapter.cc |
+++ b/net/socket/socket_bio_adapter.cc |
@@ -9,11 +9,13 @@ |
#include <algorithm> |
#include "base/bind.h" |
+#include "base/feature_list.h" |
#include "base/location.h" |
#include "base/logging.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "net/base/io_buffer.h" |
#include "net/base/net_errors.h" |
+#include "net/socket/socket.h" |
#include "net/socket/stream_socket.h" |
#include "net/ssl/openssl_ssl_util.h" |
#include "third_party/boringssl/src/include/openssl/bio.h" |
@@ -87,8 +89,19 @@ int SocketBIOAdapter::BIORead(char* out, int len) { |
DCHECK(!read_buffer_); |
DCHECK_EQ(0, read_offset_); |
read_buffer_ = new IOBuffer(read_buffer_capacity_); |
- int result = socket_->Read(read_buffer_.get(), read_buffer_capacity_, |
- read_callback_); |
+ int result = ERR_READ_IF_READY_NOT_IMPLEMENTED; |
+ if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { |
+ result = socket_->ReadIfReady( |
+ read_buffer_.get(), read_buffer_capacity_, |
+ base::Bind(&SocketBIOAdapter::OnSocketReadIfReadyComplete, |
+ weak_factory_.GetWeakPtr())); |
+ if (result == ERR_IO_PENDING) |
+ read_buffer_ = nullptr; |
+ } |
+ if (result == ERR_READ_IF_READY_NOT_IMPLEMENTED) { |
+ result = socket_->Read(read_buffer_.get(), read_buffer_capacity_, |
+ read_callback_); |
+ } |
if (result == ERR_IO_PENDING) { |
read_result_ = ERR_IO_PENDING; |
} else { |
@@ -146,6 +159,16 @@ void SocketBIOAdapter::OnSocketReadComplete(int result) { |
delegate_->OnReadReady(); |
} |
+void SocketBIOAdapter::OnSocketReadIfReadyComplete(int result) { |
+ DCHECK_EQ(ERR_IO_PENDING, read_result_); |
+ DCHECK_GE(OK, result); |
+ |
+ // Do not use HandleSocketReadResult() because result == OK doesn't mean EOF. |
+ read_result_ = result; |
+ |
+ delegate_->OnReadReady(); |
+} |
+ |
int SocketBIOAdapter::BIOWrite(const char* in, int len) { |
if (len <= 0) |
return len; |