Skip to content
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

[IN PROGRESS] Update to mio 0.7 and tokio 0.3 #9

Merged
merged 15 commits into from Dec 31, 2020
Merged

[IN PROGRESS] Update to mio 0.7 and tokio 0.3 #9

merged 15 commits into from Dec 31, 2020

Conversation

witchof0x20
Copy link
Contributor

@witchof0x20 witchof0x20 commented Oct 26, 2020

This is my attempt at updating to mio 0.7, as referenced in #6

This is likely not entirely correct, and I plan to go back over it some time this week. Putting it up as a PR to make it easier to see changes.

@witchof0x20
Copy link
Contributor Author

witchof0x20 commented Oct 26, 2020

Tested this using
main.rs

use futures::executor;
use futures::stream::StreamExt;
use std::thread;
use tokio_udev::{EventType, MonitorBuilder};

#[tokio::main]
async fn main() {
    let mut monitor = MonitorBuilder::new()
        .unwrap()
        .match_subsystem("usb")
        .unwrap()
        .listen()
        .unwrap();

    loop {
        if let Some(event) = monitor.next().await {
            println!("{}", event.event_type());
            for property in event.device().properties() {
                println!("{:?} = {:?}", property.name(), property.value());
            }
        }
    }
}

Cargo.toml:

futures = "0.3"
tokio-udev = {path = "../tokio-udev/tokio-udev"}
tokio = { version = "0.3", features = ["full"] }

and it works great

With tokio-udev from cargo, I actually get
thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime'
with this code. I haven't dug into making my example code work with instantiating the reactor yet.

I did some additional testing, and it seems this PR would also allow for bumping this project's tokio dependency to 0.3. There are no compilation errors, and the example code works.

@witchof0x20
Copy link
Contributor Author

witchof0x20 commented Oct 26, 2020

https://github.com/jeandudey/tokio-udev/blob/master/tokio-udev/examples/usb_hotplug.rs
works with this PR
It doesn't work with tokio 0.3 (not in this PR), but that's for a separate PR I think

@jeandudey
Copy link
Owner

@witchof0x20 did it not work with udev-rs@0.5? To merge #10 first and then merge the tokio update code (when done).

tokio-udev/src/lib.rs Outdated Show resolved Hide resolved
@witchof0x20
Copy link
Contributor Author

@witchof0x20 did it not work with udev-rs@0.5? To merge #10 first and then merge the tokio update code (when done).

It works with udev-rs@0.5, I just split it up because that one is an easy merge, while this is a bit more complicated.

@witchof0x20
Copy link
Contributor Author

Getting back to this, as I'm more free now. As I understand it, I would modify tokio_udev::Inner such that it wraps AsyncFd<MonitorSocket> (with an AsRawFd trait implementation that's just a wrapper for MonitorSocket::fd).

Then, AsyncFd::poll_read_ready can be used to poll the MonitorSocket for availability, pulling events out of it if possible. But that requires a &mut core::task::Context, and I'm not sure where to grab that from, as I'm not super familiar with how modern tokio works anymore.

tokio-udev/Cargo.toml Outdated Show resolved Hide resolved
tokio-udev/src/lib.rs Outdated Show resolved Hide resolved
tokio-udev/src/lib.rs Outdated Show resolved Hide resolved
@witchof0x20
Copy link
Contributor Author

witchof0x20 commented Dec 17, 2020

I think I got this working with AsyncFd. The example compiles and runs, with some changes to be compatible with updated tokio.

Requesting review from @jeandudey

@witchof0x20 witchof0x20 changed the title [IN PROGRESS] Update to mio 0.7 [IN PROGRESS] Update to mio 0.7 and tokio 0.3 Dec 17, 2020
@jeandudey jeandudey merged commit 3e37b9e into jeandudey:master Dec 31, 2020
@jeandudey
Copy link
Owner

Thanks for your contribution! Will add the changes to the CHANGELOG.md and release a new version as soon as possible.

@jeandudey
Copy link
Owner

Released 0.4.0 of both crates with recent changes and 0.5.0 with udev 0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants