Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "net/socket/socket.h" |
| 6 #define NET_SOCKET_SOCKET_H_ | |
| 7 | 6 |
| 8 #include <stdint.h> | 7 #include "net/base/net_errors.h" |
| 9 | |
| 10 #include "net/base/completion_callback.h" | |
| 11 #include "net/base/net_export.h" | |
| 12 | 8 |
| 13 namespace net { | 9 namespace net { |
| 14 | 10 |
| 15 class IOBuffer; | 11 const char Socket::kReadIfReadyTrialName[] = "SocketReadIfReady"; |
|
davidben
2017/02/01 22:25:57
I think base::Feature is the preferred way to do t
xunjieli
2017/02/03 16:35:33
Done. Neat!
| |
| 16 | 12 |
| 17 // Represents a read/write socket. | 13 int Socket::ReadIfReady(IOBuffer* buf, |
| 18 class NET_EXPORT Socket { | 14 int buf_len, |
| 19 public: | 15 const CompletionCallback& callback) { |
| 20 virtual ~Socket() {} | 16 return ERR_READ_IF_READY_NOT_IMPLEMENTED; |
| 21 | 17 } |
| 22 // 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. | |
| 24 // 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 | |
| 26 // 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 | |
| 28 // 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 | |
| 30 // the provided buffer until the callback is invoked or the socket is | |
| 31 // closed. If the socket is Disconnected before the read completes, the | |
| 32 // callback will not be invoked. | |
| 33 virtual int Read(IOBuffer* buf, int buf_len, | |
| 34 const CompletionCallback& callback) = 0; | |
| 35 | |
| 36 // 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 | |
| 38 // is returned upon failure. ERR_SOCKET_NOT_CONNECTED should be returned if | |
| 39 // 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 | |
| 41 // 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 | |
| 43 // operation is not completed immediately, the socket acquires a reference to | |
| 44 // the provided buffer until the callback is invoked or the socket is | |
| 45 // 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 | |
| 47 // Disconnected before the write completes, the callback will not be invoked. | |
| 48 virtual int Write(IOBuffer* buf, int buf_len, | |
| 49 const CompletionCallback& callback) = 0; | |
| 50 | |
| 51 // Set the receive buffer size (in bytes) for the socket. | |
| 52 // Note: changing this value can affect the TCP window size on some platforms. | |
| 53 // Returns a net error code. | |
| 54 virtual int SetReceiveBufferSize(int32_t size) = 0; | |
| 55 | |
| 56 // Set the send buffer size (in bytes) for the socket. | |
| 57 // Note: changing this value can affect the TCP window size on some platforms. | |
| 58 // Returns a net error code. | |
| 59 virtual int SetSendBufferSize(int32_t size) = 0; | |
| 60 }; | |
| 61 | 18 |
| 62 } // namespace net | 19 } // namespace net |
| 63 | |
| 64 #endif // NET_SOCKET_SOCKET_H_ | |
| OLD | NEW |