1 /* 2 * Copyright 2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 #ifndef BUFFER_QUEUE_H 9 #define BUFFER_QUEUE_H 10 11 12 #include "tcp.h" 13 14 #include <util/DoublyLinkedList.h> 15 16 17 typedef DoublyLinkedList<struct net_buffer, DoublyLinkedListCLink<struct net_buffer> > SegmentList; 18 19 class BufferQueue { 20 public: 21 BufferQueue(size_t maxBytes); 22 ~BufferQueue(); 23 24 void SetMaxBytes(size_t maxBytes); 25 void SetInitialSequence(tcp_sequence sequence); 26 27 void Add(net_buffer *buffer); 28 void Add(net_buffer *buffer, tcp_sequence sequence); 29 status_t RemoveUntil(tcp_sequence sequence); 30 status_t Get(net_buffer *buffer, tcp_sequence sequence, size_t bytes); 31 status_t Get(size_t bytes, bool remove, net_buffer **_buffer); 32 33 size_t Available() const { return fContiguousBytes; } 34 size_t Available(tcp_sequence sequence) const; 35 36 size_t PushedData() const { return fPushPointer > fFirstSequence ? fPushPointer - fFirstSequence : 0; } 37 void SetPushPointer(tcp_sequence sequence); 38 39 size_t Used() const { return fNumBytes; } 40 size_t Free() const { return fMaxBytes - fNumBytes; } 41 42 bool IsContiguous() const { return fNumBytes == fContiguousBytes; } 43 44 tcp_sequence FirstSequence() const { return fFirstSequence; } 45 tcp_sequence LastSequence() const { return fLastSequence; } 46 tcp_sequence NextSequence() const { return fFirstSequence + fContiguousBytes; } 47 48 private: 49 SegmentList fList; 50 size_t fMaxBytes; 51 size_t fNumBytes; 52 size_t fContiguousBytes; 53 tcp_sequence fFirstSequence; 54 tcp_sequence fLastSequence; 55 tcp_sequence fPushPointer; 56 }; 57 58 #endif // BUFFER_QUEUE_H 59