[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | dab9c7d | 2010-02-06 21:44:32 | [diff] [blame] | 5 | #ifndef NET_SPDY_SPDY_IO_BUFFER_H_ |
6 | #define NET_SPDY_SPDY_IO_BUFFER_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 8 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 10 | #include "net/base/io_buffer.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
[email protected] | 66a4b6d | 2011-05-19 23:36:16 | [diff] [blame] | 12 | #include "net/spdy/spdy_stream.h" |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 13 | |
14 | namespace net { | ||||
15 | |||||
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 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 | ||||
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 19 | // completion of the IO can notify the appropriate stream of completion. |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 20 | class NET_EXPORT_PRIVATE SpdyIOBuffer { |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 21 | public: |
22 | // Constructor | ||||
23 | // |buffer| is the actual data buffer. | ||||
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 24 | // |size| is the size of the data buffer. |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 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. | ||||
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 28 | SpdyIOBuffer(IOBuffer* buffer, int size, int priority, SpdyStream* stream); |
29 | SpdyIOBuffer(); | ||||
30 | ~SpdyIOBuffer(); | ||||
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 31 | |
32 | // Accessors. | ||||
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 33 | DrainableIOBuffer* buffer() const { return buffer_; } |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 34 | size_t size() const { return buffer_->size(); } |
[email protected] | 9f7c4fd | 2009-11-24 18:50:15 | [diff] [blame] | 35 | void release(); |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 36 | int priority() const { return priority_; } |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 37 | const scoped_refptr<SpdyStream>& stream() const { return stream_; } |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 38 | |
39 | // Comparison operator to support sorting. | ||||
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 40 | bool operator<(const SpdyIOBuffer& other) const { |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 41 | if (priority_ != other.priority_) |
42 | return priority_ > other.priority_; | ||||
43 | return position_ > other.position_; | ||||
44 | } | ||||
45 | |||||
46 | private: | ||||
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 47 | scoped_refptr<DrainableIOBuffer> buffer_; |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 48 | int priority_; |
49 | uint64 position_; | ||||
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 50 | scoped_refptr<SpdyStream> stream_; |
[email protected] | a164005 | 2009-10-29 21:24:02 | [diff] [blame] | 51 | static uint64 order_; // Maintains a FIFO order for equal priorities. |
52 | }; | ||||
53 | |||||
54 | } // namespace net | ||||
55 | |||||
[email protected] | dab9c7d | 2010-02-06 21:44:32 | [diff] [blame] | 56 | #endif // NET_SPDY_SPDY_IO_BUFFER_H_ |