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

Unified Diff: net/socket/socket_bio_adapter.cc

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Rebased Created 3 years, 9 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
« no previous file with comments | « net/socket/socket_bio_adapter.h ('k') | net/socket/socket_bio_adapter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « net/socket/socket_bio_adapter.h ('k') | net/socket/socket_bio_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698