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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « net/base/net_error_list.h ('k') | net/socket/socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SOCKET_SOCKET_H_ 5 #ifndef NET_SOCKET_SOCKET_H_
6 #define NET_SOCKET_SOCKET_H_ 6 #define NET_SOCKET_SOCKET_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/feature_list.h"
10 #include "net/base/completion_callback.h" 11 #include "net/base/completion_callback.h"
11 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 class IOBuffer; 16 class IOBuffer;
16 17
17 // Represents a read/write socket. 18 // Represents a read/write socket.
18 class NET_EXPORT Socket { 19 class NET_EXPORT Socket {
19 public: 20 public:
21 // Name of the field trial for using ReadyIfReady() instead of Read().
22 static const base::Feature kReadIfReadyExperiment;
23
20 virtual ~Socket() {} 24 virtual ~Socket() {}
21 25
22 // Reads data, up to |buf_len| bytes, from the socket. The number of bytes 26 // Reads data, up to |buf_len| bytes, from the socket. The number of bytes
23 // read is returned, or an error is returned upon failure. 27 // read is returned, or an error is returned upon failure.
24 // ERR_SOCKET_NOT_CONNECTED should be returned if the socket is not currently 28 // ERR_SOCKET_NOT_CONNECTED should be returned if the socket is not currently
25 // connected. Zero is returned once to indicate end-of-file; the return value 29 // connected. Zero is returned once to indicate end-of-file; the return value
26 // of subsequent calls is undefined, and may be OS dependent. ERR_IO_PENDING 30 // of subsequent calls is undefined, and may be OS dependent. ERR_IO_PENDING
27 // is returned if the operation could not be completed synchronously, in which 31 // is returned if the operation could not be completed synchronously, in which
28 // case the result will be passed to the callback when available. If the 32 // case the result will be passed to the callback when available. If the
29 // operation is not completed immediately, the socket acquires a reference to 33 // operation is not completed immediately, the socket acquires a reference to
30 // the provided buffer until the callback is invoked or the socket is 34 // the provided buffer until the callback is invoked or the socket is
31 // closed. If the socket is Disconnected before the read completes, the 35 // closed. If the socket is Disconnected before the read completes, the
32 // callback will not be invoked. 36 // callback will not be invoked.
33 virtual int Read(IOBuffer* buf, int buf_len, 37 virtual int Read(IOBuffer* buf, int buf_len,
34 const CompletionCallback& callback) = 0; 38 const CompletionCallback& callback) = 0;
35 39
40 // Reads data, up to |buf_len| bytes, into |buf| without blocking. Default
41 // implementation returns ERR_READ_IF_READY_NOT_IMPLEMENTED. Caller should
42 // fall back to Read() if receives ERR_READ_IF_READY_NOT_IMPLEMENTED.
43 // Upon synchronous completion, returns the number of bytes read, or 0 on EOF,
44 // or an error code if an error happens. If read cannot be completed
45 // synchronously, returns ERR_IO_PENDING and does not hold on to |buf|.
46 // |callback| will be invoked with OK when data can be read, at which point,
47 // caller can call ReadIfReady() again. If an error occurs asynchronously,
48 // |callback| will be invoked with the error code.
49 virtual int ReadIfReady(IOBuffer* buf,
50 int buf_len,
51 const CompletionCallback& callback);
52
36 // Writes data, up to |buf_len| bytes, to the socket. Note: data may be 53 // Writes data, up to |buf_len| bytes, to the socket. Note: data may be
37 // written partially. The number of bytes written is returned, or an error 54 // written partially. The number of bytes written is returned, or an error
38 // is returned upon failure. ERR_SOCKET_NOT_CONNECTED should be returned if 55 // is returned upon failure. ERR_SOCKET_NOT_CONNECTED should be returned if
39 // the socket is not currently connected. The return value when the 56 // the socket is not currently connected. The return value when the
40 // connection is closed is undefined, and may be OS dependent. ERR_IO_PENDING 57 // connection is closed is undefined, and may be OS dependent. ERR_IO_PENDING
41 // is returned if the operation could not be completed synchronously, in which 58 // is returned if the operation could not be completed synchronously, in which
42 // case the result will be passed to the callback when available. If the 59 // case the result will be passed to the callback when available. If the
43 // operation is not completed immediately, the socket acquires a reference to 60 // operation is not completed immediately, the socket acquires a reference to
44 // the provided buffer until the callback is invoked or the socket is 61 // the provided buffer until the callback is invoked or the socket is
45 // closed. Implementations of this method should not modify the contents 62 // closed. Implementations of this method should not modify the contents
46 // of the actual buffer that is written to the socket. If the socket is 63 // of the actual buffer that is written to the socket. If the socket is
47 // Disconnected before the write completes, the callback will not be invoked. 64 // Disconnected before the write completes, the callback will not be invoked.
48 virtual int Write(IOBuffer* buf, int buf_len, 65 virtual int Write(IOBuffer* buf, int buf_len,
49 const CompletionCallback& callback) = 0; 66 const CompletionCallback& callback) = 0;
50 67
51 // Set the receive buffer size (in bytes) for the socket. 68 // Set the receive buffer size (in bytes) for the socket.
52 // Note: changing this value can affect the TCP window size on some platforms. 69 // Note: changing this value can affect the TCP window size on some platforms.
53 // Returns a net error code. 70 // Returns a net error code.
54 virtual int SetReceiveBufferSize(int32_t size) = 0; 71 virtual int SetReceiveBufferSize(int32_t size) = 0;
55 72
56 // Set the send buffer size (in bytes) for the socket. 73 // Set the send buffer size (in bytes) for the socket.
57 // Note: changing this value can affect the TCP window size on some platforms. 74 // Note: changing this value can affect the TCP window size on some platforms.
58 // Returns a net error code. 75 // Returns a net error code.
59 virtual int SetSendBufferSize(int32_t size) = 0; 76 virtual int SetSendBufferSize(int32_t size) = 0;
60 }; 77 };
61 78
62 } // namespace net 79 } // namespace net
63 80
64 #endif // NET_SOCKET_SOCKET_H_ 81 #endif // NET_SOCKET_SOCKET_H_
OLDNEW
« 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