Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4a69aee authored by Myles Watson's avatar Myles Watson
Browse files

Gatt Rust: Convince rustc that OwnedHandle is used

OwnedHandle is dropped when a connection is dropped with a
Pending transaction.  Removing this will change the behavior.

warning: field `0` is never read
  --> src/gatt/server/att_server_bearer.rs:37:13
   |
37 |     Pending(OwnedHandle<()>),
   |     ------- ^^^^^^^^^^^^^^^
   |     |
   |     field in this variant
   |
   = note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
   |
37 |     Pending(()),
   |

Bug: 330185853
Test: atest libbluetooth_core_rs_test
Flag: EXEMPT, build-only change
Change-Id: I00d61e2a1f91667931edf0beaea7961c5e00296b
parent 29e69ca6
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ use super::{

enum AttRequestState<T: AttDatabase> {
    Idle(AttRequestHandler<T>),
    Pending(Option<OwnedHandle<()>>),
    Pending { _task: OwnedHandle<()> },
    Replacing,
}

/// The errors that can occur while trying to send a packet
@@ -153,7 +154,7 @@ impl<T: AttDatabase + Clone + 'static> WeakBoxRef<'_, AttServerBearer<T>> {
    }

    fn handle_request(&self, packet: AttView<'_>) {
        let curr_request = self.curr_request.replace(AttRequestState::Pending(None));
        let curr_request = self.curr_request.replace(AttRequestState::Replacing);
        self.curr_request.replace(match curr_request {
            AttRequestState::Idle(mut request_handler) => {
                // even if the MTU is updated afterwards, 5.3 3F 3.4.2.2 states that the
@@ -187,13 +188,16 @@ impl<T: AttDatabase + Clone + 'static> WeakBoxRef<'_, AttServerBearer<T>> {
                        })
                    });
                });
                AttRequestState::Pending(Some(task.into()))
                AttRequestState::Pending { _task: task.into() }
            }
            AttRequestState::Pending(_) => {
            AttRequestState::Pending { .. } => {
                warn!("multiple ATT operations cannot simultaneously take place, dropping one");
                // TODO(aryarahul) - disconnect connection here;
                curr_request
            }
            AttRequestState::Replacing => {
              panic!("Replacing is an ephemeral state");
            }
        });
    }
}
@@ -367,8 +371,13 @@ mod test {
            });
            conn.as_ref().handle_packet(req2.view());
            // handle first reply
            let MockDatastoreEvents::Read(TCB_IDX, VALID_HANDLE, AttributeBackingType::Characteristic, data_resp) =
                data_rx.recv().await.unwrap() else {
            let MockDatastoreEvents::Read(
                TCB_IDX,
                VALID_HANDLE,
                AttributeBackingType::Characteristic,
                data_resp,
            ) = data_rx.recv().await.unwrap()
            else {
                unreachable!();
            };
            data_resp.send(Ok(data.clone())).unwrap();