blob: a541bda170adfa0f1a01fb6dc4ef496b67b1f272 [file] [log] [blame]
Kristian Monsenddb351d2011-06-28 21:49:31 +01001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Ben Murdochc407dc52010-07-29 17:14:53 +01002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_SPDY_SPDY_IO_BUFFER_H_
6#define NET_SPDY_SPDY_IO_BUFFER_H_
Iain Merrick3345a682010-10-19 14:37:37 +01007#pragma once
Ben Murdochc407dc52010-07-29 17:14:53 +01008
Kristian Monsenddb351d2011-06-28 21:49:31 +01009#include "base/memory/ref_counted.h"
Ben Murdochc407dc52010-07-29 17:14:53 +010010#include "net/base/io_buffer.h"
11
12namespace net {
13
14class SpdyStream;
15
16// 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
19// completion of the IO can notify the appropriate stream of completion.
20class SpdyIOBuffer {
21 public:
22 // Constructor
23 // |buffer| is the actual data buffer.
24 // |size| is the size of the data buffer.
25 // |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.
28 SpdyIOBuffer(IOBuffer* buffer, int size, int priority, SpdyStream* stream);
29 SpdyIOBuffer();
30 ~SpdyIOBuffer();
31
32 // Accessors.
33 DrainableIOBuffer* buffer() const { return buffer_; }
34 size_t size() const { return buffer_->size(); }
35 void release();
36 int priority() const { return priority_; }
37 const scoped_refptr<SpdyStream>& stream() const { return stream_; }
38
39 // Comparison operator to support sorting.
40 bool operator<(const SpdyIOBuffer& other) const {
41 if (priority_ != other.priority_)
42 return priority_ > other.priority_;
43 return position_ > other.position_;
44 }
45
46 private:
47 scoped_refptr<DrainableIOBuffer> buffer_;
48 int priority_;
49 uint64 position_;
50 scoped_refptr<SpdyStream> stream_;
51 static uint64 order_; // Maintains a FIFO order for equal priorities.
52};
53
54} // namespace net
55
56#endif // NET_SPDY_SPDY_IO_BUFFER_H_