Index: net/http/bidirectional_stream.h |
diff --git a/net/http/bidirectional_stream.h b/net/http/bidirectional_stream.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cfa51355a02b15b8ac8379c1e13d55230486ec9d |
--- /dev/null |
+++ b/net/http/bidirectional_stream.h |
@@ -0,0 +1,89 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
+#define NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
+ |
+#include "base/macros.h" |
+#include "net/base/net_export.h" |
+#include "net/base/request_priority.h" |
+#include "net/http/http_request_info.h" |
+#include "net/spdy/spdy_session.h" |
+#include "net/spdy/spdy_stream.h" |
+ |
+namespace net { |
+ |
+struct HttpRequestInfo; |
+class IOBuffer; |
+class BoundNetLog; |
+ |
+// An interface that exposes bidirectional streaming. Note that only one |
+// ReadData or SendData should be in flight until the operation completes |
+// synchronously or asynchronously. |
+class NET_EXPORT BidirectionalStream { |
+ public: |
+ // Delegate to handle BidirectionalStream events. |
+ class Delegate { |
+ public: |
+ Delegate() {} |
+ |
+ // Called when an error occurs. E.g. when a connection to the server cannot |
+ // be established. |
+ virtual void OnFailed(int error) = 0; |
+ |
+ // Called when the request headers have been sent. |
+ virtual void OnRequestHeadersSent() = 0; |
+ |
+ // Called when response headers are received. |
+ virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0; |
+ |
+ // Called when read is completed asynchronously. |bytes_read| specifies how |
+ // much data is available. |
+ virtual void OnReadCompleted(int bytes_read) = 0; |
+ |
+ // Called when the entire buffer passed through SendData is sent. |
+ virtual void OnDataSent() = 0; |
+ |
+ // Called when trailers are received. |
+ virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; |
+ |
+ // Called when the stream is closed. No other delegate functions will be |
+ // called after this. |status| is an error code or OK. |
+ virtual void OnClose(int status) = 0; |
+ |
+ protected: |
+ virtual ~Delegate() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
+ }; |
+ |
+ BidirectionalStream() {} |
+ virtual ~BidirectionalStream() {} |
+ |
+ // Starts the BidirectionalStream and sends request headers. |
+ virtual void Start(const HttpRequestInfo* request_info, |
+ RequestPriority priority, |
+ const BoundNetLog& net_log, |
+ Delegate* delegate) = 0; |
+ |
+ // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, |
+ // or ERR_IO_PENDING if the read is to be completed asynchronously. |
+ virtual int ReadData(IOBuffer* buf, int buf_len) = 0; |
+ |
+ // Sends data. This should not be called again until OnDataSent is invoked. |
+ virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; |
+ |
+ // Cancels the stream. No Delegate method will be called. |
+ virtual void Cancel() = 0; |
+ |
+ // TODO(xunjieli): implement a method to do flow control. |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |