diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-02-26 20:05:33 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-03-02 12:05:06 +0100 |
commit | 5fc6e010a58409e73e19bd89b540f8c77bd8d397 (patch) | |
tree | d4b9246d93827c4d127767e328ed5396b4f2719c /src/llc.cpp | |
parent | 55f06c3d77563d5817107247c422d3e66115c352 (diff) |
llc_queue::{dequeue,enqueue}() refactor
As seen in OS#4420, setting the MetaInfo.recv_time outside of
llc_queue before calling llc_queue::enqueue() and later on using that
value in llc_queue itself at dequeue time is not a good idea, since it
can provoke errors if the recv_time was not set correctly.
For instance, LlcTest was not setting the value for recv_time on some
test, which ended up with a huge millisec value when substracting now()
from it:
"""
llc.cpp:215:29: runtime error: signed integer overflow: 1582738663 * 1000 cannot be represented in type 'long int'
"""
This issue only appeared when started building on a raspberrypi4.
Let's better set/store the MetaInfo.recv_time internally during
llc_queue::enqueue(). Then, enqueue() only needs the
MetaInfo.expire_time, so let's change its arg list to only receive that
to avoid confusions.
Take the chance to move the llc_queue APIs to use osmo_gettimeofday,
since we need to fake the time now that the API itself sets that time.
Also take the chance during this refactor to disallow passing null
pointer by default since no user needs that.
Finally, update the LlcTest accordingly with all API/behavior changes.
Related: OS#4420
Change-Id: Ief6b1464dc779ff22adc2b02da7a006cd772ebce
Diffstat (limited to 'src/llc.cpp')
-rw-r--r-- | src/llc.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/llc.cpp b/src/llc.cpp index b1550635..4cd0cc45 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -103,18 +103,19 @@ void gprs_llc_queue::init() m_avg_queue_delay = 0; } -void gprs_llc_queue::enqueue(struct msgb *llc_msg, const MetaInfo *info) + +void gprs_llc_queue::enqueue(struct msgb *llc_msg, const struct timeval *expire_time) { - static const MetaInfo def_meta = {{0}}; MetaInfo *meta_storage; - osmo_static_assert(sizeof(*info) <= sizeof(llc_msg->cb), info_does_not_fit); + osmo_static_assert(sizeof(*meta_storage) <= sizeof(llc_msg->cb), info_does_not_fit); m_queue_size += 1; m_queue_octets += msgb_length(llc_msg); meta_storage = (MetaInfo *)&llc_msg->cb[0]; - *meta_storage = info ? *info : def_meta; + osmo_gettimeofday(&meta_storage->recv_time, NULL); + meta_storage->expire_time = *expire_time; msgb_enqueue(&m_queue, llc_msg); } @@ -208,7 +209,7 @@ struct msgb *gprs_llc_queue::dequeue(const MetaInfo **info) m_queue_octets -= msgb_length(msg); /* take the second time */ - gettimeofday(&tv_now, NULL); + osmo_gettimeofday(&tv_now, NULL); tv = (struct timeval *)&msg->data[sizeof(*tv)]; timersub(&tv_now, &meta_storage->recv_time, &tv_result); @@ -234,7 +235,7 @@ void gprs_llc_queue::calc_pdu_lifetime(BTS *bts, const uint16_t pdu_delay_csec, /* calculate timestamp of timeout */ struct timeval now, csec; - gettimeofday(&now, NULL); + osmo_gettimeofday(&now, NULL); csec.tv_usec = (delay_csec % 100) * 10000; csec.tv_sec = delay_csec / 100; |