Prevent dropping a device while a control transfer is pending
This commit is contained in:
parent
dac6f52c27
commit
4a9c3e5bbc
2 changed files with 16 additions and 12 deletions
|
|
@ -323,24 +323,26 @@ impl LinuxDevice {
|
|||
}
|
||||
|
||||
pub fn control_in(
|
||||
&self,
|
||||
self: Arc<Self>,
|
||||
data: ControlIn,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>> {
|
||||
let t = TransferData::new_control_in(data);
|
||||
TransferFuture::new(t, |t| self.submit_timeout(t, timeout)).map(|t| {
|
||||
TransferFuture::new(t, |t| self.submit_timeout(t, timeout)).map(move |t| {
|
||||
drop(self); // ensure device stays alive
|
||||
t.status()?;
|
||||
Ok(t.control_in_data().to_owned())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn control_out(
|
||||
&self,
|
||||
self: Arc<Self>,
|
||||
data: ControlOut,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<(), TransferError>> {
|
||||
let t = TransferData::new_control_out(data);
|
||||
TransferFuture::new(t, |t| self.submit_timeout(t, timeout)).map(|t| {
|
||||
TransferFuture::new(t, |t| self.submit_timeout(t, timeout)).map(move |t| {
|
||||
drop(self); // ensure device stays alive
|
||||
t.status()?;
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -570,7 +572,7 @@ impl LinuxInterface {
|
|||
data: ControlIn,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>> {
|
||||
self.device.control_in(data, timeout)
|
||||
self.device.clone().control_in(data, timeout)
|
||||
}
|
||||
|
||||
pub fn control_out(
|
||||
|
|
@ -578,7 +580,7 @@ impl LinuxInterface {
|
|||
data: ControlOut,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<(), TransferError>> {
|
||||
self.device.control_out(data, timeout)
|
||||
self.device.clone().control_out(data, timeout)
|
||||
}
|
||||
|
||||
pub fn get_alt_setting(&self) -> u8 {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ impl MacDevice {
|
|||
}
|
||||
|
||||
pub fn control_in(
|
||||
self: &Arc<Self>,
|
||||
self: Arc<Self>,
|
||||
data: ControlIn,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>> {
|
||||
|
|
@ -244,7 +244,8 @@ impl MacDevice {
|
|||
noDataTimeout: timeout,
|
||||
};
|
||||
|
||||
TransferFuture::new(t, |t| self.submit_control(Direction::In, t, req)).map(|t| {
|
||||
TransferFuture::new(t, |t| self.submit_control(Direction::In, t, req)).map(move |t| {
|
||||
drop(self); // ensure device stays alive
|
||||
t.status()?;
|
||||
let t = ManuallyDrop::new(t);
|
||||
Ok(unsafe { Vec::from_raw_parts(t.buf, t.actual_len as usize, t.capacity as usize) })
|
||||
|
|
@ -252,7 +253,7 @@ impl MacDevice {
|
|||
}
|
||||
|
||||
pub fn control_out(
|
||||
self: &Arc<Self>,
|
||||
self: Arc<Self>,
|
||||
data: ControlOut,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<(), TransferError>> {
|
||||
|
|
@ -273,7 +274,8 @@ impl MacDevice {
|
|||
noDataTimeout: timeout,
|
||||
};
|
||||
|
||||
TransferFuture::new(t, |t| self.submit_control(Direction::Out, t, req)).map(|t| {
|
||||
TransferFuture::new(t, |t| self.submit_control(Direction::Out, t, req)).map(move |t| {
|
||||
drop(self); // ensure device stays alive
|
||||
t.status()?;
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -382,7 +384,7 @@ impl MacInterface {
|
|||
data: ControlIn,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>> {
|
||||
self.device.control_in(data, timeout)
|
||||
self.device.clone().control_in(data, timeout)
|
||||
}
|
||||
|
||||
pub fn control_out(
|
||||
|
|
@ -390,7 +392,7 @@ impl MacInterface {
|
|||
data: ControlOut,
|
||||
timeout: Duration,
|
||||
) -> impl MaybeFuture<Output = Result<(), TransferError>> {
|
||||
self.device.control_out(data, timeout)
|
||||
self.device.clone().control_out(data, timeout)
|
||||
}
|
||||
|
||||
pub fn endpoint(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue