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

Unified Diff: net/socket/socket_bio_adapter.cc

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: self review. remove unused include 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_bio_adapter.cc
diff --git a/net/socket/socket_bio_adapter.cc b/net/socket/socket_bio_adapter.cc
index 0d75e68ec85890a2def5983dfdb1a4332a8d81e3..35d4475a425c438e286e4cd41cbd44140c702ff1 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) {
Bence 2017/03/03 16:33:40 Should this callback not call socket_->ReadIfReady
xunjieli 2017/03/03 19:41:05 Nope. The user of SocketBIOAdapter, SSLClientSocke
+ DCHECK_EQ(ERR_IO_PENDING, read_result_);
+ DCHECK_GE(OK, result);
+
+ // Do not use HandleSocketReadResult() because |result == OK| doesn't mean EOF
Bence 2017/03/03 16:33:40 End sentence with full stop.
xunjieli 2017/03/03 19:41:05 Done.
+ read_result_ = result;
+
+ delegate_->OnReadReady();
+}
+
int SocketBIOAdapter::BIOWrite(const char* in, int len) {
if (len <= 0)
return len;

Powered by Google App Engine
This is Rietveld 408576698