net: Add trim_back to packet
This commit is contained in:
@@ -213,6 +213,7 @@ public:
|
||||
void append(packet&& p);
|
||||
|
||||
void trim_front(size_t how_much);
|
||||
void trim_back(size_t how_much);
|
||||
|
||||
// get a header pointer, linearizing if necessary
|
||||
template <typename Header>
|
||||
@@ -485,6 +486,23 @@ void packet::trim_front(size_t how_much) {
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void packet::trim_back(size_t how_much) {
|
||||
assert(how_much <= _impl->_len);
|
||||
_impl->_len -= how_much;
|
||||
size_t i = _impl->_nr_frags - 1;
|
||||
while (how_much && how_much >= _impl->_frags[i].size) {
|
||||
how_much -= _impl->_frags[i--].size;
|
||||
}
|
||||
_impl->_nr_frags = i + 1;
|
||||
if (how_much) {
|
||||
_impl->_frags[i].size -= how_much;
|
||||
if (i == 0 && _impl->using_internal_data()) {
|
||||
_impl->_headroom += how_much;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Header>
|
||||
Header*
|
||||
packet::prepend_header(size_t extra_size) {
|
||||
|
||||
Reference in New Issue
Block a user