Skip to content

Commit

Permalink
make sure, that the link layer stopps as soon, as the LL_TERMINATE_IN…
Browse files Browse the repository at this point in the history
…D PDU is acknowledged
  • Loading branch information
TorstenRobitzki committed Sep 26, 2023
1 parent 3cff669 commit 5f4132b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bluetoe/link_layer/include/bluetoe/link_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,11 @@ namespace link_layer {

const auto time_since_last_event = this->time_since_last_event();

if ( time_since_last_event < connection_timeout_
if ( state_ == state::disconnecting && termination_send_ && !this->pending_outgoing_data_available() )
{
force_disconnect();
}
else if ( time_since_last_event < connection_timeout_
&& !( state_ == state::connecting && time_since_last_event >= ( num_windows_til_timeout - 1 ) * connection_interval_ ) )
{
this->plan_next_connection_event_after_timeout( connection_interval_ );
Expand Down Expand Up @@ -1003,7 +1007,9 @@ namespace link_layer {
* and has to be offset by 1 to see if there is a pending instant at this connection
* event.
*/
if ( handle_received_data() == ll_result::disconnect || send_control_pdus() == ll_result::disconnect )
if ( ( state_ == state::disconnecting && termination_send_ && !this->pending_outgoing_data_available() )
|| handle_received_data() == ll_result::disconnect
|| send_control_pdus() == ll_result::disconnect )
{
force_disconnect();
}
Expand Down Expand Up @@ -1414,6 +1420,7 @@ namespace link_layer {
} );

this->commit_ll_transmit_buffer( output );
this->stop_ll_pdu_buffer();
termination_send_ = true;
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/link_layer/ll_control_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,18 @@ BOOST_FIXTURE_TEST_CASE( local_disconnect_requested_with_reason, default_connect

BOOST_CHECK_EQUAL( num_terminates, 1 );
}

BOOST_FIXTURE_TEST_CASE( local_disconnect_stop_sending_after_ack, default_connected<> )
{
ll_function_call([&]{
this->disconnect( 0x42 );
});
ll_empty_pdus(100);

end_of_simulation( bluetoe::link_layer::delta_time::seconds( 30 ) );
run();

BOOST_CHECK_LT( connection_events().back().start_receive,
bluetoe::link_layer::delta_time::msec( 100 ) );
BOOST_CHECK_LT( connection_events().size(), 4 );
}

0 comments on commit 5f4132b

Please sign in to comment.