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

Unified Diff: net/socket/socket.h

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Self 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.h
diff --git a/net/socket/socket.h b/net/socket/socket.h
index cda54063f3059e76726c896b5e6ae87508a5f483..306c40d62726d5860604676e6c05fa1b1876e7c6 100644
--- a/net/socket/socket.h
+++ b/net/socket/socket.h
@@ -7,6 +7,7 @@
#include <stdint.h>
+#include "base/feature_list.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
@@ -17,6 +18,9 @@ class IOBuffer;
// Represents a read/write socket.
class NET_EXPORT Socket {
public:
+ // Name of the field trial for using ReadyIfReady() instead of Read().
+ static const base::Feature kReadIfReadyExperiment;
+
virtual ~Socket() {}
// Reads data, up to |buf_len| bytes, from the socket. The number of bytes
@@ -33,6 +37,19 @@ class NET_EXPORT Socket {
virtual int Read(IOBuffer* buf, int buf_len,
const CompletionCallback& callback) = 0;
+ // Reads as much data as possible into |buf| without blocking. Default
+ // implementation returns ERR_READ_IF_READY_NOT_IMPLEMENTED. Caller should
+ // fall back to Read() if receives ERR_READ_IF_READY_NOT_IMPLEMENTED.
+ // Upon synchronous completion, returns the number of bytes read or an error
+ // code if an error happens; If read cannot be completed synchronously,
+ // returns ERR_IO_PENDING and does not hold on to |buf|. |callback| will be
+ // invoked with OK when data can be read, at which point, caller can call
+ // ReadIfReady() again; if an error occurs asynchronously, |callback| will be
+ // invoked with the error code.
davidben 2017/02/10 23:33:48 Hrm. One thing I noticed that's actually quite sub
xunjieli 2017/02/13 20:28:18 Acknowledged. Yes, that's right. I have edited the
+ virtual int ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
+
// Writes data, up to |buf_len| bytes, to the socket. Note: data may be
// written partially. The number of bytes written is returned, or an error
// is returned upon failure. ERR_SOCKET_NOT_CONNECTED should be returned if

Powered by Google App Engine
This is Rietveld 408576698