Chromium Code Reviews| 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..6367d859801278e1c84f64e2cf7798d4cf5f5d00 |
| --- /dev/null |
| +++ b/net/http/bidirectional_stream.h |
| @@ -0,0 +1,86 @@ |
| +// 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; |
| + |
| +class NET_EXPORT BidirectionalStream { |
|
mmenke
2015/10/21 18:05:52
Need some class level docs.
xunjieli
2015/10/21 19:35:36
Done.
|
| + 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 data 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; |
|
mef
2015/10/20 21:56:35
Will there be distinction between OnClose and OnCa
xunjieli
2015/10/21 19:35:36
Not in the underlying implementation. But I think
|
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Delegate); |
| + }; |
| + |
| + BidirectionalStream() {} |
| + virtual ~BidirectionalStream() {} |
|
mmenke
2015/10/21 18:05:52
Don't think we should inline anything in this file
xunjieli
2015/10/21 19:35:36
What do you mean by inlining? Sorry, I am still a
mmenke
2015/10/21 19:46:14
Put method bodies with the declaration. You shoul
xunjieli
2015/10/21 20:22:19
I see! Done. Thanks
|
| + |
| + // 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 util OnDataSent is invoked. |
|
mef
2015/10/20 21:56:34
until. Is OnDataSent invoked when entire buffer is
xunjieli
2015/10/21 19:35:36
Done. Yes, OnDataSent is invoked when the entire b
|
| + virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; |
| + |
| + // Cancels the stream. Delegate::OnClose will be invoked if the stream is |
| + // canceled. |
|
mmenke
2015/10/21 18:05:52
I'd recommend against this behavior - we've run in
xunjieli
2015/10/21 19:35:36
Done. Good idea! That makes it easier to reason.
|
| + virtual void Cancel() = 0; |
| + |
| + // TODO(xunjieli): implement a method to do flow control. |
| + private: |
|
mmenke
2015/10/21 18:05:52
nit: Blank line before private.
xunjieli
2015/10/21 19:35:36
Done.
|
| + DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |