| Index: net/spdy/spdy_session.h
|
| diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
|
| index 0c35cf90e0c4797100ee80899e0ff25fa2da6f0b..1bee18605f386af78ad566958537a9480034dfd2 100644
|
| --- a/net/spdy/spdy_session.h
|
| +++ b/net/spdy/spdy_session.h
|
| @@ -94,6 +94,32 @@ COMPILE_ASSERT(PROTOCOL_ERROR_UNEXPECTED_PING ==
|
| class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| public BufferedSpdyFramerVisitorInterface {
|
| public:
|
| + // Defines an interface for producing SpdyIOBuffers.
|
| + class NET_EXPORT_PRIVATE SpdyIOBufferProducer {
|
| + public:
|
| + SpdyIOBufferProducer() {}
|
| +
|
| + // Returns a newly created SpdyIOBuffer, owned by the caller, or NULL
|
| + // if not buffer is ready to be produced.
|
| + virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) = 0;
|
| +
|
| + virtual RequestPriority GetPriority() const = 0;
|
| +
|
| + virtual ~SpdyIOBufferProducer() {}
|
| +
|
| + protected:
|
| + // Activates |spdy_stream| in |spdy_session|.
|
| + static void ActivateStream(SpdySession* spdy_session,
|
| + SpdyStream* spdy_stream);
|
| +
|
| + static SpdyIOBuffer* CreateIOBuffer(SpdyFrame* frame,
|
| + RequestPriority priority,
|
| + SpdyStream* spdy_stream);
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(SpdyIOBufferProducer);
|
| + };
|
| +
|
| // Create a new SpdySession.
|
| // |host_port_proxy_pair| is the host/port that this session connects to, and
|
| // the proxy configuration settings that it's using.
|
| @@ -157,9 +183,12 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| // authentication now.
|
| bool VerifyDomainAuthentication(const std::string& domain);
|
|
|
| + // Records that |stream| has a write available.
|
| + void SetStreamHasWriteAvailable(SpdyStream* stream);
|
| +
|
| // Send the SYN frame for |stream_id|. This also sends PING message to check
|
| // the status of the connection.
|
| - int WriteSynStream(
|
| + SpdySynStreamControlFrame* CreateSynStream(
|
| SpdyStreamId stream_id,
|
| RequestPriority priority,
|
| uint8 credential_slot,
|
| @@ -167,21 +196,24 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| const linked_ptr<SpdyHeaderBlock>& headers);
|
|
|
| // Write a CREDENTIAL frame to the session.
|
| - int WriteCredentialFrame(const std::string& origin,
|
| - SSLClientCertType type,
|
| - const std::string& key,
|
| - const std::string& cert,
|
| - RequestPriority priority);
|
| + SpdyCredentialControlFrame* CreateCredentialFrame(const std::string& origin,
|
| + SSLClientCertType type,
|
| + const std::string& key,
|
| + const std::string& cert,
|
| + RequestPriority priority);
|
|
|
| // Write a data frame to the stream.
|
| // Used to create and queue a data frame for the given stream.
|
| - int WriteStreamData(SpdyStreamId stream_id, net::IOBuffer* data,
|
| - int len,
|
| - SpdyDataFlags flags);
|
| + SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id,
|
| + net::IOBuffer* data, int len,
|
| + SpdyDataFlags flags);
|
|
|
| // Close a stream.
|
| void CloseStream(SpdyStreamId stream_id, int status);
|
|
|
| + // Close a stream that has been created but is not yet active.
|
| + void CloseCreatedStream(SpdyStream* stream, int status);
|
| +
|
| // Reset a stream by sending a RST_STREAM frame with given status code.
|
| // Also closes the stream. Was not piggybacked to CloseStream since not
|
| // all of the calls to CloseStream necessitate sending a RST_STREAM.
|
| @@ -272,7 +304,7 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
|
|
| // Returns true if session is not currently active
|
| bool is_active() const {
|
| - return !active_streams_.empty();
|
| + return !active_streams_.empty() || !created_streams_.empty();
|
| }
|
|
|
| // Access to the number of active and pending streams. These are primarily
|
| @@ -281,6 +313,7 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| size_t num_unclaimed_pushed_streams() const {
|
| return unclaimed_pushed_streams_.size();
|
| }
|
| + size_t num_created_streams() const { return created_streams_.size(); }
|
|
|
| // Returns true if flow control is enabled for the session.
|
| bool is_flow_control_enabled() const {
|
| @@ -356,7 +389,18 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| typedef std::map<int, scoped_refptr<SpdyStream> > ActiveStreamMap;
|
| // Only HTTP push a stream.
|
| typedef std::map<std::string, scoped_refptr<SpdyStream> > PushedStreamMap;
|
| - typedef std::priority_queue<SpdyIOBuffer> OutputQueue;
|
| + typedef std::set<scoped_refptr<SpdyStream> > CreatedStreamSet;
|
| + typedef std::map<SpdyIOBufferProducer*, SpdyStream*> StreamProducerMap;
|
| + class SpdyIOBufferProducerCompare {
|
| + public:
|
| + bool operator() (const SpdyIOBufferProducer* lhs,
|
| + const SpdyIOBufferProducer* rhs) const {
|
| + return lhs->GetPriority() < rhs->GetPriority();
|
| + }
|
| + };
|
| + typedef std::priority_queue<SpdyIOBufferProducer*,
|
| + std::vector<SpdyIOBufferProducer*>,
|
| + SpdyIOBufferProducerCompare> WriteQueue;
|
|
|
| struct CallbackResultPair {
|
| CallbackResultPair(const CompletionCallback& callback_in, int result_in)
|
| @@ -434,9 +478,7 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| // Queue a frame for sending.
|
| // |frame| is the frame to send.
|
| // |priority| is the priority for insertion into the queue.
|
| - // |stream| is the stream which this IO is associated with (or NULL).
|
| - void QueueFrame(SpdyFrame* frame, RequestPriority priority,
|
| - SpdyStream* stream);
|
| + void QueueFrame(SpdyFrame* frame, RequestPriority priority);
|
|
|
| // Track active streams in the active stream list.
|
| void ActivateStream(SpdyStream* stream);
|
| @@ -566,8 +608,16 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
|
| // server, but do not have consumers yet.
|
| PushedStreamMap unclaimed_pushed_streams_;
|
|
|
| - // As we gather data to be sent, we put it into the output queue.
|
| - OutputQueue queue_;
|
| + // Set of all created streams but that have not yet sent any frames.
|
| + CreatedStreamSet created_streams_;
|
| +
|
| + // As streams have data to be sent, we put them into the write queue.
|
| + WriteQueue write_queue_;
|
| +
|
| + // Mapping from SpdyIOBufferProducers to their corresponding SpdyStream
|
| + // so that when a stream is destroyed, we can remove the corresponding
|
| + // producer from |write_queue_|
|
| + StreamProducerMap stream_producers_;
|
|
|
| // The packet we are currently sending.
|
| bool write_pending_; // Will be true when a write is in progress.
|
|
|