Skip to content

Commit

Permalink
net: add UnwindSafe impl to PollEvented (#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hodkinson committed Jan 8, 2022
1 parent 553cc3b commit ac2343d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tokio/src/io/poll_evented.rs
Expand Up @@ -4,6 +4,7 @@ use mio::event::Source;
use std::fmt;
use std::io;
use std::ops::Deref;
use std::panic::{RefUnwindSafe, UnwindSafe};

cfg_io_driver! {
/// Associates an I/O resource that implements the [`std::io::Read`] and/or
Expand Down Expand Up @@ -185,6 +186,10 @@ feature! {
}
}

impl<E: Source> UnwindSafe for PollEvented<E> {}

impl<E: Source> RefUnwindSafe for PollEvented<E> {}

impl<E: Source> Deref for PollEvented<E> {
type Target = E;

Expand Down
32 changes: 32 additions & 0 deletions tokio/tests/net_types_unwind.rs
@@ -0,0 +1,32 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

use std::panic::{RefUnwindSafe, UnwindSafe};

#[test]
fn net_types_are_unwind_safe() {
is_unwind_safe::<tokio::net::TcpListener>();
is_unwind_safe::<tokio::net::TcpSocket>();
is_unwind_safe::<tokio::net::TcpStream>();
is_unwind_safe::<tokio::net::UdpSocket>();
}

#[test]
#[cfg(unix)]
fn unix_net_types_are_unwind_safe() {
is_unwind_safe::<tokio::net::UnixDatagram>();
is_unwind_safe::<tokio::net::UnixListener>();
is_unwind_safe::<tokio::net::UnixStream>();
}

#[test]
#[cfg(windows)]
fn windows_net_types_are_unwind_safe() {
use tokio::net::windows::named_pipe::NamedPipeClient;
use tokio::net::windows::named_pipe::NamedPipeServer;

is_unwind_safe::<NamedPipeClient>();
is_unwind_safe::<NamedPipeServer>();
}

fn is_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {}

0 comments on commit ac2343d

Please sign in to comment.