Skip to content

Commit

Permalink
fix for #281, no longer panic if disconnect() called while already di…
Browse files Browse the repository at this point in the history
…sconnecting
  • Loading branch information
peter9477 committed Dec 3, 2024
1 parent c4e6287 commit c74bdf1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nrf-softdevice/src/ble/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ impl ConnectionState {
}

let ret = unsafe { raw::sd_ble_gap_disconnect(conn_handle, reason.into()) };
// This case can occur in normal operation if e.g. the connection was
// already being disconnected when disconnect() is called, so
// return as error instead of a panic.
if ret == raw::NRF_ERROR_INVALID_STATE {
return Err(DisconnectedError);
}
unwrap!(RawError::convert(ret), "sd_ble_gap_disconnect");

self.disconnecting = true;
Expand Down

0 comments on commit c74bdf1

Please sign in to comment.