From 345d3a3628b03bb9c07fdb4ac6a99714e8929dfd Mon Sep 17 00:00:00 2001 From: Asias He Date: Tue, 4 Nov 2014 14:52:10 +0800 Subject: [PATCH] net: Add trim_back to packet --- net/packet.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/packet.hh b/net/packet.hh index 11c5fde6d8..7ddb139c7f 100644 --- a/net/packet.hh +++ b/net/packet.hh @@ -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 @@ -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 Header* packet::prepend_header(size_t extra_size) {