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

Unified Diff: net/socket/socket.h

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/base/net_error_list.h ('k') | net/socket/socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/socket.h
diff --git a/net/socket/socket.h b/net/socket/socket.h
index cda54063f3059e76726c896b5e6ae87508a5f483..8f5fed6dea08a65799468a23e1328a73d7af7a12 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 data, up to |buf_len| bytes, 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 0 on EOF,
+ // 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.
+ 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
« no previous file with comments | « net/base/net_error_list.h ('k') | net/socket/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698