OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // HttpStream is an interface for reading and writing data to an HttpStream that |
| 6 // keeps the client agnostic of the actual underlying transport layer. This |
| 7 // provides an abstraction for both a basic http stream as well as http |
| 8 // pipelining implementations. |
| 9 // |
| 10 // NOTE(willchan): This interface is a work in progress. It will most likely |
| 11 // change, since for a pipelining implementation, the stream needs to contain |
| 12 // the http parsing code. For symmetry, the writing methods will probably |
| 13 // contain the code for constructing http requests. |
| 14 |
| 15 #ifndef NET_HTTP_HTTP_STREAM_H_ |
| 16 #define NET_HTTP_HTTP_STREAM_H_ |
| 17 |
| 18 #include "base/basictypes.h" |
| 19 #include "net/base/completion_callback.h" |
| 20 |
| 21 namespace net { |
| 22 |
| 23 class IOBuffer; |
| 24 |
| 25 class HttpStream { |
| 26 public: |
| 27 HttpStream() {} |
| 28 virtual ~HttpStream() {} |
| 29 |
| 30 // Reads data, up to buf_len bytes, from the socket. The number of bytes |
| 31 // read is returned, or an error is returned upon failure. Zero is returned |
| 32 // to indicate end-of-file. ERR_IO_PENDING is returned if the operation |
| 33 // could not be completed synchronously, in which case the result will be |
| 34 // passed to the callback when available. If the operation is not completed |
| 35 // immediately, the socket acquires a reference to the provided buffer until |
| 36 // the callback is invoked or the socket is destroyed. |
| 37 virtual int Read(IOBuffer* buf, |
| 38 int buf_len, |
| 39 CompletionCallback* callback) = 0; |
| 40 |
| 41 // Writes data, up to buf_len bytes, to the socket. Note: only part of the |
| 42 // data may be written! The number of bytes written is returned, or an error |
| 43 // is returned upon failure. ERR_IO_PENDING is returned if the operation |
| 44 // could not be completed synchronously, in which case the result will be |
| 45 // passed to the callback when available. If the operation is not completed |
| 46 // immediately, the socket acquires a reference to the provided buffer until |
| 47 // the callback is invoked or the socket is destroyed. |
| 48 // Implementations of this method should not modify the contents of the actual |
| 49 // buffer that is written to the socket. |
| 50 virtual int Write(IOBuffer* buf, |
| 51 int buf_len, |
| 52 CompletionCallback* callback) = 0; |
| 53 |
| 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(HttpStream); |
| 56 }; |
| 57 |
| 58 } // namespace net |
| 59 |
| 60 #endif // NET_HTTP_HTTP_STREAM_H_ |
OLD | NEW |