| 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..1d111e51a357674ce5fe2ab52ae28869c720ffed 100644
|
| --- a/net/socket/socket_bio_adapter.cc
|
| +++ b/net/socket/socket_bio_adapter.cc
|
| @@ -11,9 +11,11 @@
|
| #include "base/bind.h"
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| +#include "base/metrics/field_trial.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,20 @@ 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::FieldTrialList::FindFullName(Socket::kReadIfReadyTrialName) ==
|
| + "enable") {
|
| + 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 {
|
| @@ -143,7 +157,17 @@ void SocketBIOAdapter::OnSocketReadComplete(int result) {
|
| DCHECK_EQ(ERR_IO_PENDING, read_result_);
|
|
|
| HandleSocketReadResult(result);
|
| - delegate_->OnReadReady();
|
| + delegate_->OnReadReady(read_result_ > 0 ? OK : read_result_);
|
| +}
|
| +
|
| +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(read_result_);
|
| }
|
|
|
| int SocketBIOAdapter::BIOWrite(const char* in, int len) {
|
| @@ -214,7 +238,7 @@ int SocketBIOAdapter::BIOWrite(const char* in, int len) {
|
| read_result_ == ERR_IO_PENDING) {
|
| base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| FROM_HERE, base::Bind(&SocketBIOAdapter::CallOnReadReady,
|
| - weak_factory_.GetWeakPtr()));
|
| + weak_factory_.GetWeakPtr(), write_error_));
|
| }
|
|
|
| return bytes_copied;
|
| @@ -271,7 +295,8 @@ void SocketBIOAdapter::OnSocketWriteComplete(int result) {
|
| // OnWriteReady.
|
| if (was_full) {
|
| base::WeakPtr<SocketBIOAdapter> guard(weak_factory_.GetWeakPtr());
|
| - delegate_->OnWriteReady();
|
| + DCHECK_GE(OK, write_error_);
|
| + delegate_->OnWriteReady(write_error_);
|
| // OnWriteReady may delete the adapter.
|
| if (!guard)
|
| return;
|
| @@ -280,12 +305,12 @@ void SocketBIOAdapter::OnSocketWriteComplete(int result) {
|
| // Write errors are fed back into BIO_read once the read buffer is empty. If
|
| // BIO_read is currently blocked, signal early that a read result is ready.
|
| if (result < 0 && read_result_ == ERR_IO_PENDING)
|
| - delegate_->OnReadReady();
|
| + delegate_->OnReadReady(result);
|
| }
|
|
|
| -void SocketBIOAdapter::CallOnReadReady() {
|
| +void SocketBIOAdapter::CallOnReadReady(int rv) {
|
| if (read_result_ == ERR_IO_PENDING)
|
| - delegate_->OnReadReady();
|
| + delegate_->OnReadReady(rv);
|
| }
|
|
|
| SocketBIOAdapter* SocketBIOAdapter::GetAdapter(BIO* bio) {
|
|
|