tokio-rs / mio

Metal I/O library for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update socket types API to match std lib

Thomasdezeeuw opened this issue · comments

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

commented

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.

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.
commented

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?

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.