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

socket2::SockRef::from() doesn't work with tokio sockets anymore #402

Closed
gregoire-mullvad opened this issue Feb 27, 2023 · 2 comments
Closed

Comments

@gregoire-mullvad
Copy link

With socket2 0.5 it is no longer possible to use SockRef::from() with a tokio socket (using tokio 1.25.0.)

The following code works with socket2 0.4:

#[tokio::main]
async fn main() {
    let tokio_socket = tokio::net::TcpSocket::new_v4().unwrap();
    let socket2_socket = socket2::SockRef::from(&tokio_socket);
}

But breaks with 0.5:

error[E0277]: the trait bound `TcpSocket: AsFd` is not satisfied
 --> src/main.rs:4:49
  |
4 |     let socket2_socket = socket2::SockRef::from(&tokio_socket);
  |                          ---------------------- ^^^^^^^^^^^^^ the trait `AsFd` is not implemented for `TcpSocket`
  |                          |
  |                          required by a bound introduced by this call
  |
  = help: the following other types implement trait `AsFd`:
            &T
            &mut T
            Arc<T>
            BorrowedFd<'_>
            Box<T>
            OwnedFd
            PidFd
            Socket
          and 20 others
  = note: required for `SockRef<'_>` to implement `From<&TcpSocket>`

For more information about this error, try `rustc --explain E0277`.
@Thomasdezeeuw
Copy link
Collaborator

Thomasdezeeuw commented Feb 27, 2023

As stated in the changelog: https://github.com/rust-lang/socket2/blob/master/CHANGELOG.md#changed:

From<S> is now implemented using the I/O traits AsFd and AsSocket

We added some safety around SockRef so now it only accepts know good fd/sockets. Tokio's types should implement AsFd and AsSocket.

@Thomasdezeeuw
Copy link
Collaborator

Also see tokio-rs/tokio#5514 for the implementations added to Tokio.

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