blob: e96c946df4788a9087336d34c304a05156c75c4a [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]a1640052009-10-29 21:24:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]dab9c7d2010-02-06 21:44:325#ifndef NET_SPDY_SPDY_IO_BUFFER_H_
6#define NET_SPDY_SPDY_IO_BUFFER_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]a1640052009-10-29 21:24:028
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/ref_counted.h"
[email protected]a1640052009-10-29 21:24:0210#include "net/base/io_buffer.h"
[email protected]172da1b2011-08-12 15:52:2611#include "net/base/net_export.h"
[email protected]66a4b6d2011-05-19 23:36:1612#include "net/spdy/spdy_stream.h"
[email protected]a1640052009-10-29 21:24:0213
14namespace net {
15
[email protected]955fc2e72010-02-08 20:37:3016// A class for managing SPDY IO buffers. These buffers need to be prioritized
17// so that the SpdySession sends them in the right order. Further, they need
18// to track the SpdyStream which they are associated with so that incremental
[email protected]a1640052009-10-29 21:24:0219// completion of the IO can notify the appropriate stream of completion.
[email protected]172da1b2011-08-12 15:52:2620class NET_EXPORT_PRIVATE SpdyIOBuffer {
[email protected]a1640052009-10-29 21:24:0221 public:
22 // Constructor
23 // |buffer| is the actual data buffer.
[email protected]bf2491a92009-11-29 16:39:4824 // |size| is the size of the data buffer.
[email protected]a1640052009-10-29 21:24:0225 // |priority| is the priority of this buffer. Lower numbers are higher
26 // priority.
27 // |stream| is a pointer to the stream which is managing this buffer.
[email protected]955fc2e72010-02-08 20:37:3028 SpdyIOBuffer(IOBuffer* buffer, int size, int priority, SpdyStream* stream);
29 SpdyIOBuffer();
30 ~SpdyIOBuffer();
[email protected]a1640052009-10-29 21:24:0231
32 // Accessors.
[email protected]bf2491a92009-11-29 16:39:4833 DrainableIOBuffer* buffer() const { return buffer_; }
[email protected]a1640052009-10-29 21:24:0234 size_t size() const { return buffer_->size(); }
[email protected]9f7c4fd2009-11-24 18:50:1535 void release();
[email protected]a1640052009-10-29 21:24:0236 int priority() const { return priority_; }
[email protected]955fc2e72010-02-08 20:37:3037 const scoped_refptr<SpdyStream>& stream() const { return stream_; }
[email protected]a1640052009-10-29 21:24:0238
39 // Comparison operator to support sorting.
[email protected]955fc2e72010-02-08 20:37:3040 bool operator<(const SpdyIOBuffer& other) const {
[email protected]a1640052009-10-29 21:24:0241 if (priority_ != other.priority_)
42 return priority_ > other.priority_;
43 return position_ > other.position_;
44 }
45
46 private:
[email protected]bf2491a92009-11-29 16:39:4847 scoped_refptr<DrainableIOBuffer> buffer_;
[email protected]a1640052009-10-29 21:24:0248 int priority_;
49 uint64 position_;
[email protected]955fc2e72010-02-08 20:37:3050 scoped_refptr<SpdyStream> stream_;
[email protected]a1640052009-10-29 21:24:0251 static uint64 order_; // Maintains a FIFO order for equal priorities.
52};
53
54} // namespace net
55
[email protected]dab9c7d2010-02-06 21:44:3256#endif // NET_SPDY_SPDY_IO_BUFFER_H_