mirror of https://github.com/smol-rs/polling
add is_connection_fail back, mark depercated
This commit is contained in:
parent
4a5d5fcb5d
commit
bcfe7a271b
|
@ -366,6 +366,14 @@ impl EventExtra {
|
|||
self.flags.contains(epoll::EventFlags::PRI)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
Some(
|
||||
self.flags.contains(epoll::EventFlags::ERR)
|
||||
&& self.flags.contains(epoll::EventFlags::HUP),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_err(&self) -> Option<bool> {
|
||||
Some(self.flags.contains(epoll::EventFlags::ERR))
|
||||
|
|
|
@ -682,6 +682,11 @@ impl EventExtra {
|
|||
self.flags.set(AfdPollMask::RECEIVE_EXPEDITED, active);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
Some(self.flags.intersects(AfdPollMask::CONNECT_FAIL))
|
||||
}
|
||||
|
||||
/// Check if TCP connect failed.
|
||||
#[inline]
|
||||
pub fn is_err(&self) -> Option<bool> {
|
||||
|
|
|
@ -372,6 +372,11 @@ impl EventExtra {
|
|||
false
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_err(&self) -> Option<bool> {
|
||||
None
|
||||
|
|
60
src/lib.rs
60
src/lib.rs
|
@ -332,6 +332,66 @@ impl Event {
|
|||
self.extra.is_pri()
|
||||
}
|
||||
|
||||
/// Tells if this event is the result of a connection failure.
|
||||
///
|
||||
/// This function checks if a TCP connection has failed. It corresponds to the `EPOLLERR` or `EPOLLHUP` event in Linux
|
||||
/// and `CONNECT_FAILED` event in Windows IOCP.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::{io, net};
|
||||
/// // Assuming polling and socket2 are included as dependencies in Cargo.toml
|
||||
/// use polling::Event;
|
||||
/// use socket2::Type;
|
||||
///
|
||||
/// fn main() -> io::Result<()> {
|
||||
/// let socket = socket2::Socket::new(socket2::Domain::IPV4, Type::STREAM, None)?;
|
||||
/// let poller = polling::Poller::new()?;
|
||||
/// unsafe {
|
||||
/// poller.add(&socket, Event::new(0, true, true))?;
|
||||
/// }
|
||||
/// let addr = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 8080);
|
||||
/// socket.set_nonblocking(true)?;
|
||||
/// let _ = socket.connect(&addr.into());
|
||||
///
|
||||
/// let mut events = polling::Events::new();
|
||||
///
|
||||
/// events.clear();
|
||||
/// poller.wait(&mut events, None)?;
|
||||
///
|
||||
/// let event = events.iter().next();
|
||||
///
|
||||
/// let event = match event {
|
||||
/// Some(event) => event,
|
||||
/// None => {
|
||||
/// println!("no event");
|
||||
/// return Ok(());
|
||||
/// },
|
||||
/// };
|
||||
///
|
||||
/// println!("event: {:?}", event);
|
||||
/// if event
|
||||
/// .is_connect_failed()
|
||||
/// .unwrap_or_default()
|
||||
/// {
|
||||
/// println!("connect failed");
|
||||
/// }
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns `Some(true)` if the connection has failed, `Some(false)` if the connection has not failed,
|
||||
/// or `None` if the platform does not support detecting this condition.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
self.extra.is_connect_failed()
|
||||
}
|
||||
|
||||
/// Tells if this event is the result of a connection failure.
|
||||
///
|
||||
/// This function checks if an error exist,particularlly useful in detecting if TCP connection failed. It corresponds to the `EPOLLERR` event in Linux
|
||||
|
|
|
@ -427,6 +427,11 @@ impl EventExtra {
|
|||
self.flags.contains(PollFlags::PRI)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
Some(self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_err(&self) -> Option<bool> {
|
||||
Some(self.flags.contains(PollFlags::ERR))
|
||||
|
|
|
@ -251,6 +251,11 @@ impl EventExtra {
|
|||
self.flags.contains(PollFlags::PRI)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_connect_failed(&self) -> Option<bool> {
|
||||
Some(self.flags.contains(PollFlags::ERR) && self.flags.contains(PollFlags::HUP))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_err(&self) -> Option<bool> {
|
||||
Some(self.flags.contains(PollFlags::ERR))
|
||||
|
|
Loading…
Reference in New Issue