1313#include < fastdds/utils/TimedConditionVariable.hpp>
1414#include < fastdds/utils/TimedMutex.hpp>
1515
16+ #include < rtps/messages/IRTPSMessageGroupLimitation.hpp>
1617#include < rtps/messages/RTPSMessageGroup.hpp>
1718#include < rtps/participant/RTPSParticipantImpl.hpp>
1819#include < rtps/writer/BaseWriter.hpp>
@@ -277,19 +278,20 @@ struct FlowControllerSyncPublishMode : public FlowControllerPureSyncPublishMode,
277278};
278279
279280// ! Sends all samples asynchronously but with bandwidth limitation.
280- struct FlowControllerLimitedAsyncPublishMode : public FlowControllerAsyncPublishMode
281+ struct FlowControllerLimitedAsyncPublishMode : public FlowControllerAsyncPublishMode , public IRTPSMessageGroupLimitation
281282{
282283 FlowControllerLimitedAsyncPublishMode (
283284 RTPSParticipantImpl* participant,
284285 const FlowControllerDescriptor* descriptor)
285286 : FlowControllerAsyncPublishMode(participant, descriptor)
287+ , sent_bytes_limitation_(static_cast <uint32_t >(descriptor->max_bytes_per_period))
286288 {
287289 assert (nullptr != descriptor);
288290 assert (0 < descriptor->max_bytes_per_period );
289291
290292 max_bytes_per_period = descriptor->max_bytes_per_period ;
291293 period_ms = std::chrono::milliseconds (descriptor->period_ms );
292- group.set_sent_bytes_limitation ( static_cast < uint32_t >(max_bytes_per_period) );
294+ group.set_limitation ( this );
293295 }
294296
295297 bool fast_check_is_there_slot_for_change (
@@ -311,7 +313,7 @@ struct FlowControllerLimitedAsyncPublishMode : public FlowControllerAsyncPublish
311313
312314 }
313315
314- bool ret = (max_bytes_per_period - group. get_current_bytes_processed () ) > size_to_check;
316+ bool ret = (max_bytes_per_period - current_sent_bytes_ ) > size_to_check;
315317
316318 if (!ret)
317319 {
@@ -345,7 +347,7 @@ struct FlowControllerLimitedAsyncPublishMode : public FlowControllerAsyncPublish
345347 {
346348 last_period_ = std::chrono::steady_clock::now ();
347349 force_wait_ = false ;
348- group. reset_current_bytes_processed () ;
350+ current_sent_bytes_ = 0 ;
349351 }
350352
351353 return reset_limit;
@@ -365,15 +367,39 @@ struct FlowControllerLimitedAsyncPublishMode : public FlowControllerAsyncPublish
365367 }
366368 }
367369
370+ void add_sent_bytes_by_group (
371+ uint32_t bytes,
372+ RTPSMessageSenderInterface&) override
373+ {
374+ current_sent_bytes_ += bytes;
375+ }
376+
377+ bool data_exceeds_limitation (
378+ CacheChange_t&,
379+ uint32_t size_to_add,
380+ uint32_t pending_to_send,
381+ RTPSMessageSenderInterface&) override
382+ {
383+ return
384+ // either limitation has already been reached
385+ (sent_bytes_limitation_ <= (current_sent_bytes_ + pending_to_send)) ||
386+ // or adding size_to_add will exceed limitation
387+ (size_to_add > (sent_bytes_limitation_ - (current_sent_bytes_ + pending_to_send)));
388+ }
389+
368390 int32_t max_bytes_per_period = 0 ;
369391
370392 std::chrono::milliseconds period_ms;
371393
372394private:
373395
374- bool force_wait_ = false ;
396+ bool force_wait_ {false };
397+
398+ std::chrono::steady_clock::time_point last_period_ {std::chrono::steady_clock::now ()};
375399
376- std::chrono::steady_clock::time_point last_period_ = std::chrono::steady_clock::now();
400+ uint32_t sent_bytes_limitation_ {0 };
401+
402+ uint32_t current_sent_bytes_ {0 };
377403};
378404
379405
@@ -1068,7 +1094,7 @@ class FlowControllerImpl : public FlowController
10681094 return get_max_payload_impl ();
10691095 }
10701096
1071- private :
1097+ protected :
10721098
10731099 /* !
10741100 * Initialize asynchronous thread.
0 commit comments