Skip to content

Commit

Permalink
Merge pull request #171 from vermasrijan19/main
Browse files Browse the repository at this point in the history
Added connection Handle check before gap event is handled in characteristic to fix the deadlock issue in #151
  • Loading branch information
taks authored Feb 12, 2025
2 parents cdb5e09 + f1c5956 commit e2aaa24
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/server/ble_characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ impl BLECharacteristic {
});
}
self
.svc_def_descriptors
.push(sys::ble_gatt_dsc_def::default());
.svc_def_descriptors
.push(sys::ble_gatt_dsc_def::default());
self.svc_def_descriptors.as_mut_ptr()
}

Expand Down Expand Up @@ -318,10 +318,13 @@ impl BLECharacteristic {
let ctxt = unsafe { &*ctxt };

let mutex = unsafe { voidp_to_ref::<Mutex<Self>>(arg) };
let Some(mut characteristic) = mutex.try_lock() else {

if crate::utilities::ble_gap_conn_find(conn_handle).is_err() {
::log::warn!("the conn handle does not exist");
return sys::BLE_ATT_ERR_UNLIKELY as _;
};
}

let mut characteristic = mutex.lock();
if unsafe { sys::ble_uuid_cmp((*ctxt.__bindgen_anon_1.chr).uuid, &characteristic.uuid.u) != 0 }
{
return sys::BLE_ATT_ERR_UNLIKELY as _;
Expand Down Expand Up @@ -401,9 +404,9 @@ impl BLECharacteristic {
}

if let Some(idx) = self
.subscribed_list
.iter()
.position(|x| x.0 == subscribe.conn_handle)
.subscribed_list
.iter()
.position(|x| x.0 == subscribe.conn_handle)
{
if !sub_val.is_empty() {
self.subscribed_list[idx].1 = sub_val;
Expand Down Expand Up @@ -442,9 +445,9 @@ impl BLECharacteristic {
impl core::fmt::Debug for BLECharacteristic {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("BLECharacteristic")
.field("uuid", &BleUuid::from(self.uuid))
.field("properties", &self.properties)
.finish()
.field("uuid", &BleUuid::from(self.uuid))
.field("properties", &self.properties)
.finish()
}
}

Expand Down

0 comments on commit e2aaa24

Please sign in to comment.