Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

async_std support? #77

Closed
manuels opened this issue May 10, 2020 · 8 comments
Closed

async_std support? #77

manuels opened this issue May 10, 2020 · 8 comments

Comments

@manuels
Copy link

manuels commented May 10, 2020

This is a well crafted crate. Thanks for implementing it!
Is there a plan to make it work with async_std instead of tokio?

@little-dude
Copy link
Owner

Hello,

That's something I'd love to have, but I have little time these days, so I'm not working on new features. However I'd gladly accept a PR for this.

Perhaps we should discuss first how to do this though. Currently, there are two places where we have tokio specific code:

@joshtriplett
Copy link

As noted in in the link to smol, the first item isn't needed at all; because you implement AsRawFd, polling just works. So you'd just need a feature flag to enable tokio support to avoid the dependency.

The second item would require some modification to use smol functions rather than tokio, so that would have to be conditional.

@gabrik
Copy link
Collaborator

gabrik commented Jan 8, 2021

I really need this support, I can take care of the implementation.
Where I should add this code? Inside the netlink-sys crate?

@little-dude
Copy link
Owner

netlink-sys already supports smol since #104.

The biggest piece is actually netlink-proto, which uses tokio in some places. Ideally I'd like to re-write these portions with non tokio specific bits, but it's not so trivial and I've been postponing this refactoring for a long time. I'd love some help with this and will take time to review any PR. Before starting it would be nice to discuss a plan though.

@gabrik
Copy link
Collaborator

gabrik commented Jan 8, 2021

Sure, I'll take a look at the code to understand what the code does and I'll come back with more thoughts on this.

@little-dude
Copy link
Owner

It's not too bad actually. I think we only use use tokio_util::codec::{Decoder, Encoder}; so we could just depend on tokio_util with the codec feature. Beyond this, we also need to change this in lib.rs:

pub mod sys {
    pub use netlink_sys::{protocols, SocketAddr, TokioSocket as Socket};
}

Maybe we can add a smol or async_std feature flag and choose another socket if compiling with that flag. By default we'd still compile with tokio support. Would that be fine? I wonder how other crates support multiple async frameworks these days.

@gabrik
Copy link
Collaborator

gabrik commented Jan 8, 2021

That is correct, other crates usually use features to select the async framework.
I guess that just depend on tokio_util and then depending on the feature we use tokio or async_std, with tokio as the default feature it is more than fine.

I also think that this feature should be re-exposed also by the creates that depend on netlink-proto in order to allow the user to select the needed one.

@JohnTitor
Copy link
Collaborator

Implemented by #144.

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

No branches or pull requests

5 participants