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..2d6f7b3e59e0452b8cf8ee686ba9e5fafd32ce30 |
| --- /dev/null |
| +++ b/net/http/bidirectional_stream.h |
| @@ -0,0 +1,82 @@ |
| +// 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 "base/memory/weak_ptr.h" |
|
mmenke
2015/10/07 18:43:33
Not needed
xunjieli
2015/10/19 21:07:46
Done.
|
| +#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 { |
| + public: |
| + // Delegate to handle BidirectionalStream events. |
| + class Delegate { |
| + public: |
| + Delegate() {} |
|
mmenke
2015/10/07 18:43:33
nit: Blank line after constructor.
xunjieli
2015/10/19 21:07:46
Done.
|
| + // Called when an error occurs. E.g. when an 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; |
|
mmenke
2015/10/07 18:43:33
This is called when all data from the last SendDat
xunjieli
2015/10/19 21:07:46
I think it is called for every SendData.
mmenke
2015/10/19 21:27:53
Right...But it's called when *all* of the data is
xunjieli
2015/10/19 21:34:31
Ah, I see! I will modify the comment to reflect th
|
| + |
| + // 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. |
|
mef
2015/10/07 23:44:56
Add a comment about values of |status|.
xunjieli
2015/10/19 21:07:46
Done.
|
| + 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. |
| + virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; |
|
mmenke
2015/10/07 18:43:33
I assume it's not legal to call again until OnData
xunjieli
2015/10/19 21:07:46
Yes, that's my understanding too. I added a commen
|
| + |
| + // TODO(xunjieli): implement a method to do flow control. |
|
mef
2015/10/07 23:44:56
Do we also need a method to explicitly close / can
xunjieli
2015/10/19 21:07:46
Done.
|
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |