/*
- * Copyright (c) 2002-2004 The Regents of The University of Michigan
+ * Copyright (c) 2004-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
class Checkpoint;
class PacketFifo
{
+ public:
+ typedef std::list<PacketPtr> fifo_list;
+ typedef fifo_list::iterator iterator;
+
protected:
std::list<PacketPtr> fifo;
int _maxsize;
return _reserved;
}
+ iterator begin() { return fifo.begin(); }
+ iterator end() { return fifo.end(); }
+
+ PacketPtr front() { return fifo.front(); }
+
bool push(PacketPtr ptr)
{
+ assert(ptr->length);
assert(_reserved <= ptr->length);
+ assert(ptr->slack == 0);
if (avail() < ptr->length - _reserved)
return false;
return true;
}
- PacketPtr front() { return fifo.front(); }
-
void pop()
{
if (empty())
return;
- _size -= fifo.front()->length;
- fifo.front() = NULL;
+ PacketPtr &packet = fifo.front();
+ _size -= packet->length;
+ _size -= packet->slack;
+ packet->slack = 0;
+ packet = NULL;
fifo.pop_front();
}
void clear()
{
+ for (iterator i = begin(); i != end(); ++i)
+ (*i)->slack = 0;
fifo.clear();
_size = 0;
_reserved = 0;
}
+ void remove(iterator i)
+ {
+ PacketPtr &packet = *i;
+ if (i != fifo.begin()) {
+ iterator prev = i;
+ --prev;
+ assert(prev != fifo.end());
+ (*prev)->slack += packet->length;
+ } else {
+ _size -= packet->length;
+ _size -= packet->slack;
+ }
+
+ packet->slack = 0;
+ packet = NULL;
+ fifo.erase(i);
+ }
+
+ bool copyout(void *dest, int offset, int len);
+
+ int countPacketsBefore(iterator end)
+ {
+ iterator i = fifo.begin();
+ int count = 0;
+
+ while (i != end) {
+ ++count;
+ ++i;
+ }
+
+ return count;
+ }
+
+ int countPacketsAfter(iterator i)
+ {
+ iterator end = fifo.end();
+ int count = 0;
+
+ while (i != end) {
+ ++count;
+ ++i;
+ }
+
+ return count;
+ }
+
+
/**
* Serialization stuff
*/