bmwill / memory-socket

An in-memory socket abstraction for Rust
Apache License 2.0
7 stars 3 forks source link

Prototype listening on SocketAddr instead of port (WIP) #4

Closed dusty-phillips closed 4 years ago

dusty-phillips commented 4 years ago

The basic idea is the same, but it better mimics the normal socket interface.

The Switchboard can now be thought of as a parody of the entire internet instead of a single machine.

Most everything is a direct mapping, but there are two uncertain situations:

Both of these could be solved by mapping to the local machine address (using e.g the get_if_addrs crate), but I'm not sure that make sense. Another option I toyed with was having a "set_connect_address" global, but that simply lacked elegance.

( Discussion in #3 )

dusty-phillips commented 4 years ago

Made most of the requested changes; awaiting guidance on whether to match the other implementations for the public poll_accept and local_addr Result.

bmwill commented 4 years ago

I think that since getting local_addr can't fail it makes most sense to keep it as being an infallible api. I would think that it would be fairly easy to Ok wrap it if you needed to implement a generic socket trait for it.

I also think that poll_accept should be kept as private. If you need to have an equivalent accept function it should be easy enough to introduce one as an async fn the only issue is that it can't really be called accept since there's already the sync accept:

    pub async fn accept_async(&mut self) -> Result<MemorySocket> {
        futures::future::poll_fn(|ctx| self.poll_accept(ctx)).await
    }

If this isn't needed now then it could probably wait to be added at a later point in time (mostly because it doesn't really relate to converting the lib to use SocketAddrs which is the primary focus of this PR)

dusty-phillips commented 4 years ago

Should have hit all the points hit now; I had them in my local directory for several days but apparently forgot to push. 🤦‍♂️

bmwill commented 4 years ago

Sorry this took me a bit to get back to, thanks for making those tweaks!