-
Notifications
You must be signed in to change notification settings - Fork 38
chore: bump tokio to v1 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ extern crate nix; | |
use std::cmp::min; | ||
use std::ffi::CStr; | ||
use std::fs::{read_dir, File, ReadDir}; | ||
use std::io::Read; | ||
use std::mem; | ||
use std::ops::Index; | ||
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; | ||
|
@@ -954,11 +955,11 @@ impl LineEventHandle { | |
/// This blocks while there is not another event available from the | ||
/// kernel for the line which matches the subscription criteria | ||
/// specified in the `event_flags` when the handle was created. | ||
pub fn get_event(&self) -> Result<LineEvent> { | ||
pub fn get_event(&mut self) -> Result<LineEvent> { | ||
match self.read_event() { | ||
Ok(Some(event)) => Ok(event), | ||
Ok(None) => Err(event_err(nix::Error::Sys(nix::errno::Errno::EIO))), | ||
Err(e) => Err(event_err(e)), | ||
Err(e) => Err(e.into()), | ||
} | ||
} | ||
|
||
|
@@ -981,19 +982,15 @@ impl LineEventHandle { | |
|
||
/// Helper function which returns the line event if a complete event was read, Ok(None) if not | ||
/// enough data was read or the error returned by `read()`. | ||
/// | ||
/// This function allows access to the raw `nix::Error` as required, for example, to theck | ||
/// whether read() returned -EAGAIN. | ||
pub(crate) fn read_event(&self) -> std::result::Result<Option<LineEvent>, nix::Error> { | ||
pub(crate) fn read_event(&mut self) -> std::io::Result<Option<LineEvent>> { | ||
let mut data: ffi::gpioevent_data = unsafe { mem::zeroed() }; | ||
let mut data_as_buf = unsafe { | ||
slice::from_raw_parts_mut( | ||
&mut data as *mut ffi::gpioevent_data as *mut u8, | ||
mem::size_of::<ffi::gpioevent_data>(), | ||
) | ||
}; | ||
let bytes_read = nix::unistd::read(self.file.as_raw_fd(), &mut data_as_buf)?; | ||
|
||
let bytes_read = self.file.read(&mut data_as_buf)?; | ||
if bytes_read != mem::size_of::<ffi::gpioevent_data>() { | ||
Ok(None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again not really related to this PR (sorry, it's just caught my attention)... do you think there is any case in which a partial read should occur during operation? i wonder whether this line is hiding dropping some data / a partial cause of #51, and whether this should instead be something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, possibly. Do you know if a gpio char device can return partial packets? Couldn't find anything about that. I couldn't repeat that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the way that the file works in the kernel for a character device, I wouldn't ever expect a read call to return a partial structure. I'll have to consider the linked issue but I don't think that branch would ever be hit in practice. |
||
} else { | ||
|
@@ -1016,7 +1013,7 @@ impl Iterator for LineEventHandle { | |
match self.read_event() { | ||
Ok(None) => None, | ||
Ok(Some(event)) => Some(Ok(event)), | ||
Err(e) => Some(Err(event_err(e))), | ||
Err(e) => Some(Err(e.into())), | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.