Index: net/socket/socket.h |
diff --git a/net/socket/socket.h b/net/socket/socket.h |
index cda54063f3059e76726c896b5e6ae87508a5f483..4876c48ddb6e3c687da6a205de0aa8d0ee9fffd3 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 |
Bence
2017/03/03 16:33:40
Optional: add a note at the beginning of the comme
xunjieli
2017/03/03 19:41:05
There is a comment about this actually in the para
|
@@ -33,6 +37,21 @@ class NET_EXPORT Socket { |
virtual int Read(IOBuffer* buf, int buf_len, |
Bence
2017/03/03 16:33:40
<rant>
I am unhappy with how a scoped_refptr is p
xunjieli
2017/03/03 19:41:05
Acknowledged. Rant acknowledged :)
|
const CompletionCallback& callback) = 0; |
+ // Reads as much data as possible into |buf| without blocking. Default |
Bence
2017/03/03 16:33:40
Optional: add a note at the beginning of the comme
Bence
2017/03/03 16:33:40
What happens if a caller calls ReadIfReady(), that
Bence
2017/03/03 16:33:40
If it reads as much data as possible, why does it
xunjieli
2017/03/03 19:41:05
I will keep it this way. I have a comment in the l
xunjieli
2017/03/03 19:41:05
Yep, it reads at most |buf_len_|. Clarified in the
xunjieli
2017/03/03 19:41:05
It should be the same as calling Read() twice when
|
+ // 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, |
Bence
2017/03/03 16:33:40
Optional: replace every semicolon with full stop t
xunjieli
2017/03/03 19:41:05
Done.
|
+ // 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 |
Bence
2017/03/03 16:33:40
Suppose ReadIfReady() returns ERR_IO_PENDING, late
xunjieli
2017/03/03 19:41:05
Nope. it's not guaranteed. It's legal for an imple
|
+ // ReadIfReady() again; if an error occurs asynchronously, |callback| will be |
+ // invoked with the error code. |
+ // Note: if 0 is returned synchronously, it means that EOF is reached; if 0/OK |
Bence
2017/03/03 16:33:40
Optional: move "if 0 is returned synchronously" in
xunjieli
2017/03/03 19:41:05
Done.
|
+ // is returned asynchronously, it means that ReadIfReady() can be retried. |
Bence
2017/03/03 16:33:40
Remove "0 is returned asynchronously" case because
xunjieli
2017/03/03 19:41:05
Done.
|
+ 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 |