OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BASE_SOCKET_H_ | 5 #ifndef NET_BASE_SOCKET_H_ |
6 #define NET_BASE_SOCKET_H_ | 6 #define NET_BASE_SOCKET_H_ |
7 | 7 |
8 #include "net/base/completion_callback.h" | 8 #include "net/base/completion_callback.h" |
| 9 #include "net/base/io_buffer.h" |
9 | 10 |
10 namespace net { | 11 namespace net { |
11 | 12 |
12 // Represents a read/write socket. | 13 // Represents a read/write socket. |
13 class Socket { | 14 class Socket { |
14 public: | 15 public: |
15 virtual ~Socket() {} | 16 virtual ~Socket() {} |
16 | 17 |
17 // Reads data, up to buf_len bytes, from the socket. The number of bytes | 18 // Reads data, up to buf_len bytes, from the socket. The number of bytes |
18 // read is returned, or an error is returned upon failure. Zero is returned | 19 // read is returned, or an error is returned upon failure. Zero is returned |
19 // to indicate end-of-file. ERR_IO_PENDING is returned if the operation | 20 // to indicate end-of-file. ERR_IO_PENDING is returned if the operation |
20 // could not be completed synchronously, in which case the result will be | 21 // could not be completed synchronously, in which case the result will be |
21 // passed to the callback when available. | 22 // passed to the callback when available. If the operation is not completed |
22 virtual int Read(char* buf, int buf_len, | 23 // immediately, the socket acquires a reference to the provided buffer until |
| 24 // the callback is invoked or the socket is destroyed. |
| 25 virtual int Read(IOBuffer* buf, int buf_len, |
23 CompletionCallback* callback) = 0; | 26 CompletionCallback* callback) = 0; |
24 | 27 |
25 // Writes data, up to buf_len bytes, to the socket. Note: only part of the | 28 // Writes data, up to buf_len bytes, to the socket. Note: only part of the |
26 // data may be written! The number of bytes written is returned, or an error | 29 // data may be written! The number of bytes written is returned, or an error |
27 // is returned upon failure. ERR_IO_PENDING is returned if the operation | 30 // is returned upon failure. ERR_IO_PENDING is returned if the operation |
28 // could not be completed synchronously, in which case the result will be | 31 // could not be completed synchronously, in which case the result will be |
29 // passed to the callback when available. | 32 // passed to the callback when available. If the operation is not completed |
30 virtual int Write(const char* buf, int buf_len, | 33 // immediately, the socket acquires a reference to the provided buffer until |
| 34 // the callback is invoked or the socket is destroyed. |
| 35 // Implementations of this method should not modify the contents of the actual |
| 36 // buffer that is written to the socket. |
| 37 virtual int Write(IOBuffer* buf, int buf_len, |
31 CompletionCallback* callback) = 0; | 38 CompletionCallback* callback) = 0; |
32 }; | 39 }; |
33 | 40 |
34 } // namespace net | 41 } // namespace net |
35 | 42 |
36 #endif // NET_BASE_SOCKET_H_ | 43 #endif // NET_BASE_SOCKET_H_ |
OLD | NEW |