OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| 6 #define NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "net/base/net_export.h" |
| 10 #include "net/base/request_priority.h" |
| 11 #include "net/http/http_request_info.h" |
| 12 #include "net/spdy/spdy_session.h" |
| 13 #include "net/spdy/spdy_stream.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 struct HttpRequestInfo; |
| 18 class IOBuffer; |
| 19 class BoundNetLog; |
| 20 |
| 21 // An interface that exposes bidirectional streaming. Note that only one |
| 22 // ReadData or SendData should be in flight until the operation completes |
| 23 // synchronously or asynchronously. |
| 24 class NET_EXPORT BidirectionalStream { |
| 25 public: |
| 26 // Delegate to handle BidirectionalStream events. |
| 27 class Delegate { |
| 28 public: |
| 29 Delegate() {} |
| 30 |
| 31 // Called when an error occurs. E.g. when a connection to the server cannot |
| 32 // be established. |
| 33 virtual void OnFailed(int error) = 0; |
| 34 |
| 35 // Called when the request headers have been sent. |
| 36 virtual void OnRequestHeadersSent() = 0; |
| 37 |
| 38 // Called when response headers are received. |
| 39 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0; |
| 40 |
| 41 // Called when read is completed asynchronously. |bytes_read| specifies how |
| 42 // much data is available. |
| 43 virtual void OnReadCompleted(int bytes_read) = 0; |
| 44 |
| 45 // Called when the entire buffer passed through SendData is sent. |
| 46 virtual void OnDataSent() = 0; |
| 47 |
| 48 // Called when trailers are received. |
| 49 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; |
| 50 |
| 51 // Called when the stream is closed. No other delegate functions will be |
| 52 // called after this. |status| is an error code or OK. |
| 53 virtual void OnClose(int status) = 0; |
| 54 |
| 55 protected: |
| 56 virtual ~Delegate() {} |
| 57 |
| 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 60 }; |
| 61 |
| 62 BidirectionalStream() {} |
| 63 virtual ~BidirectionalStream() {} |
| 64 |
| 65 // Starts the BidirectionalStream and sends request headers. |
| 66 virtual void Start(const HttpRequestInfo* request_info, |
| 67 RequestPriority priority, |
| 68 const BoundNetLog& net_log, |
| 69 Delegate* delegate) = 0; |
| 70 |
| 71 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, |
| 72 // or ERR_IO_PENDING if the read is to be completed asynchronously. |
| 73 virtual int ReadData(IOBuffer* buf, int buf_len) = 0; |
| 74 |
| 75 // Sends data. This should not be called again until OnDataSent is invoked. |
| 76 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; |
| 77 |
| 78 // Cancels the stream. No Delegate method will be called. |
| 79 virtual void Cancel() = 0; |
| 80 |
| 81 // TODO(xunjieli): implement a method to do flow control. |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| 85 }; |
| 86 |
| 87 } // namespace net |
| 88 |
| 89 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
OLD | NEW |