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

Update socket types API to match std lib #1750

Open
Thomasdezeeuw opened this issue Dec 24, 2023 · 5 comments
Open

Update socket types API to match std lib #1750

Thomasdezeeuw opened this issue Dec 24, 2023 · 5 comments

Comments

@Thomasdezeeuw
Copy link
Collaborator

Need to check if we're missing any API compared to the types found in the standard library.

@Thomasdezeeuw Thomasdezeeuw added this to the v1.0 milestone Dec 24, 2023
@tglane
Copy link
Contributor

tglane commented Mar 26, 2024

I checked the API of the socket types of the master branch oof mio and compared them with the current version in the standard library (1.77.0). The following functions are not implemented for the mio socket types.

UdpSocket:
Functions:

  • try_clone

Traits:

  • AsFd
  • AsSocket
  • From<OwnedFd> (and vice versa)
  • From<OwnedSocket> (and vice versa)

TcpStream:
Functions:

  • linger (nightly)
  • set_linger (nightly)
  • try_clone

Traits:

  • AsFd
  • AsSocket
  • From<OwnedFd> (and vice versa)
  • From<OwnedSocket> (and vice versa)

TcpListener:
Functions:

  • incoming
  • into_incoming (nightly)
  • try_clone
    Traits:
  • AsFd
  • AsSocket
  • From<OwnedFd> (and vice versa)
  • From<OwnedSocket> (and vice versa)
  • TcpListenerExt (only for WASI target with one nightly function)

UnixDatagram:
Functions:

  • bind_addr
  • connect_addr
  • passcred (nighlty)
  • set_passcred (nightly)
  • peek (nightly)
  • peek_from (nightly)
  • recv_vectored_with_ancillary(_from) (nightly)
  • send_vectored_with_ancillary(_from) (nightly)
  • send_to_addr
  • set_mark (nightly)
  • try_clone

Traits:

  • AsFd
  • From<OwnedFd> (and vice versa)

UnixStream:
Functions:

  • passcred (nighlty)
  • set_passcred (nightly)
  • `peek (nightly)
  • peer_cred (nightly)
  • recv_vectored_with_ancillary(_from) (nightly)
  • send_vectored_with_ancillary(_from) (nightly)
  • set_mark (nightly)
  • try_clone

Traits:

  • AsFd
  • From<OwnedFd> (and vice versa)

UnixListener:
Functions:

  • incoming

Traits:

  • AsFd
  • From<OwnedFd> (and vice versa)

Apart from the missing functions/traits that I listed above there are function on all sockets missing that in my opinion are pointless to implement for mio because they refer to the timeout of blocking operations or set the nonblocking flag:

  • read_timeout
  • set_read_timeout
  • write_timeout
  • set_write_timeout
  • connect_timeout
  • set_nonblocking

I hope this little summary is somewhat helpful.

@Thomasdezeeuw
Copy link
Collaborator Author

I checked the API of the socket types of the master branch oof mio and compared them with the current version in the standard library (1.77.0). The following functions are not implemented for the mio socket types.

Thanks @tglane

UdpSocket: Functions:

* `try_clone`

Cloning with Mio is a bad idea, so I don't think we should add these.

Traits:

* `AsFd`

* `AsSocket`

* `From<OwnedFd>` (and vice versa)

* `From<OwnedSocket>` (and vice versa)

I/O safety traits are being added here: #1745.

TcpStream: Functions:

* `linger` (nightly)

* `set_linger` (nightly)

This we can add.

* `try_clone`

No cloning, see above.

Traits:

* `AsFd`

* `AsSocket`

* `From<OwnedFd>` (and vice versa)

* `From<OwnedSocket>` (and vice versa)

Being added in #1745.

TcpListener: Functions:

* `incoming`

* `into_incoming` (nightly)

These don't really work as we have an iterator that would return WouldBlock errors, not an ideal API I think.

* `try_clone`

No cloning.

  Traits:

* `AsFd`

* `AsSocket`

* `From<OwnedFd>` (and vice versa)

* `From<OwnedSocket>` (and vice versa)

I/O traits again.

* `TcpListenerExt` (only for WASI target with one nightly function)

Not sure about this, currently unstable so we'll wait and see.

UnixDatagram: Functions:

* `bind_addr`

* `connect_addr`

Could look into these after #1749.

* `passcred` (nighlty)

* `set_passcred` (nightly)

* `peek` (nightly)

* `peek_from` (nightly)

* `recv_vectored_with_ancillary(_from)` (nightly)

* `send_vectored_with_ancillary(_from)` (nightly)

* `send_to_addr`

* `set_mark` (nightly)

I think we can skip these nightly-only API, these have been unstable for years now.

* `try_clone`

No cloning.

Traits:

* `AsFd`

* `From<OwnedFd>` (and vice versa)

More I/O traits.

UnixStream: Functions:

* `passcred` (nighlty)

* `set_passcred` (nightly)

* `peek (nightly)

* `peer_cred` (nightly)

* `recv_vectored_with_ancillary(_from)` (nightly)

* `send_vectored_with_ancillary(_from)` (nightly)

* `set_mark` (nightly)

* `try_clone`

Same as above, unstable and cloning API.

Traits:

* `AsFd`

* `From<OwnedFd>` (and vice versa)

I/O traits.

UnixListener: Functions:

* `incoming`

Same as for TcpListener.

Traits:

* `AsFd`

* `From<OwnedFd>` (and vice versa)

More I/O traits.

Apart from the missing functions/traits that I listed above there are function on all sockets missing that in my opinion are pointless to implement for mio because they refer to the timeout of blocking operations or set the nonblocking flag:

* `read_timeout`

* `set_read_timeout`

* `write_timeout`

* `set_write_timeout`

* `connect_timeout`

* `set_nonblocking`

Again.

I hope this little summary is somewhat helpful.

Very much so, thank you!

TL;DR:

  • TcpStream::(set_)linger
  • UnixDatagram::{bind,connect,send_to}_addr.

@tglane
Copy link
Contributor

tglane commented Mar 26, 2024

Traits:

  • AsFd

  • AsSocket

  • From<OwnedFd> (and vice versa)

  • From<OwnedSocket> (and vice versa)

Being added in #1745.

Correct me if I'm wrong here, but in the mentioned PR only the trait AsFd is implemented for the socket types, isn't it? So the other trait impls should be added there as well(?)

Should we wait wiith adding TcpStream::(set_)linger until it is stabilized, or would that be fine to be implemented wile still being nightly in the std?

@Thomasdezeeuw
Copy link
Collaborator Author

Correct me if I'm wrong here, but in the mentioned PR only the trait AsFd is implemented for the socket types, isn't it? So the other trait impls should be added there as well(?)

Good point.

Should we wait wiith adding TcpStream::(set_)linger until it is stabilized, or would that be fine to be implemented wile still being nightly in the std?

Yes, in the (somewhat unlikely) case that the API changes in std lib.

@Thomasdezeeuw
Copy link
Collaborator Author

Postponing this until after a v1 since we can always add more API.

@Thomasdezeeuw Thomasdezeeuw removed this from the v1.0 milestone Jun 9, 2024
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

No branches or pull requests

2 participants