lemunozm / message-io

Fast and easy-to-use event-driven network library.
Apache License 2.0
1.12k stars 75 forks source link

Is it possible to create an UART adapter? #162

Open MGlolenstine opened 1 year ago

MGlolenstine commented 1 year ago

I've tried looking into making a custom adapter, but the ConnectionInfo requires SocketAddr which only supports IPv4 and IPv6, which UART doesn't have.

Would it be possible to implement connect_with without having to specify an IP address?

I've looked around for a bit and I think that one of the actions I could take, is to fork it and add COM/TTY support to ConnectionInfo and RemoteAddr.

EDIT: I know that the point of this library is networking, but I like the design and I thought it would make my interfacing with UART easier.

lemunozm commented 1 year ago

Hi @MGlolenstine, glad to hear you're creating a UART adapter. I like the idea 🙌🏻.

Sure it would need some kind of refactoring/redesign. I think the first question is, how to identify UARTs connections?

The SocketAddr returned by connect_with ends up in the Endpoint type used everywhere. I think the first change will be to allow the Endpoint type to hold several kinds of connections:

pub enum Addr {
    Network(SocketAddr),
    Device(/* UART addr here*/ )
}

pub struct Endpoint {
    resource_id: ResourceId,
    addr: Addr,
}

Then, you can now return an Addr::Device() from the connect_with() function. WDYT?

MGlolenstine commented 1 year ago

I have to admit that I've only barely scratched the surface of the library, and the above ideas I've gotten from the documentation (which is excellent, by the way). Your idea will probably be much better than what I had, and I'll take a look later today and see if I can create a nice abstraction :)

Thank you!

lemunozm commented 1 year ago

Great! and any suggestion or other idea you feel fits better is welcome!