From 9cd790291f1a305aed6ee24bca499f821ffb3bf1 Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 11:29:09 -0500 Subject: [PATCH 01/14] add is connect failed --- Cargo.toml | 1 + examples/tcp_client.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/iocp/mod.rs | 6 ++++++ src/lib.rs | 8 ++++++++ 4 files changed, 56 insertions(+) create mode 100644 examples/tcp_client.rs diff --git a/Cargo.toml b/Cargo.toml index af87214..4ee2d75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ features = [ [dev-dependencies] easy-parallel = "3.1.0" fastrand = "2.0.0" +socket2 = "0.5.5" [target.'cfg(unix)'.dev-dependencies] libc = "0.2" diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs new file mode 100644 index 0000000..0a71cf3 --- /dev/null +++ b/examples/tcp_client.rs @@ -0,0 +1,41 @@ +use std::{io, net}; + +use polling::Event; +use socket2::Type; +use tracing::event; + +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 mut res = socket.connect(&addr.into()); + + let mut events = polling::Events::new(); + while let Err(ref e) = res { + if e.kind() != io::ErrorKind::WouldBlock { + return Err(io::Error::new(e.kind(), e.to_string())); + } + + events.clear(); + poller.wait(&mut events, None)?; + + let event = events.iter().next(); + if event.is_none() { + println!("no event"); + break; + } + + let event = event.unwrap(); + println!("event: {:?}", event); + if event.is_connect_failed() { + println!("connect failed"); + break; + } + } + + Ok(()) +} diff --git a/src/iocp/mod.rs b/src/iocp/mod.rs index 5168e76..1f37062 100644 --- a/src/iocp/mod.rs +++ b/src/iocp/mod.rs @@ -681,6 +681,12 @@ impl EventExtra { pub fn set_pri(&mut self, active: bool) { self.flags.set(AfdPollMask::RECEIVE_EXPEDITED, active); } + + /// Check if TCP connect failed. + #[inline] + pub fn is_connect_failed(&self) -> bool { + self.flags.intersects(AfdPollMask::CONNECT_FAIL) + } } /// A packet used to wake up the poller with an event. diff --git a/src/lib.rs b/src/lib.rs index 4caf19a..1870e63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,6 +332,14 @@ impl Event { self.extra.is_pri() } + /// Tell if this event is the result of a connect failure. + /// + /// This indicates that a non-blocking connect operation has failed. + #[inline] + pub fn is_connect_failed(&self) -> bool { + self.extra.is_connect_failed() + } + /// Remove any extra information from this event. #[inline] pub fn clear_extra(&mut self) { From 7d587d86a5235b170dd6c72c4a642499fd59ac0b Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:15:13 -0500 Subject: [PATCH 02/14] update linux --- examples/tcp_client.rs | 17 ++++++++--------- src/epoll.rs | 5 +++++ src/lib.rs | 5 ++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index 0a71cf3..aa9d708 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -2,7 +2,6 @@ use std::{io, net}; use polling::Event; use socket2::Type; -use tracing::event; fn main() -> io::Result<()> { let socket = socket2::Socket::new(socket2::Domain::IPV4, Type::STREAM, None)?; @@ -12,13 +11,13 @@ fn main() -> io::Result<()> { } let addr = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 8080); socket.set_nonblocking(true)?; - let mut res = socket.connect(&addr.into()); + let res = socket.connect(&addr.into()); let mut events = polling::Events::new(); - while let Err(ref e) = res { - if e.kind() != io::ErrorKind::WouldBlock { - return Err(io::Error::new(e.kind(), e.to_string())); - } + // while let Err(ref e) = res { + // if e.kind() != io::ErrorKind::WouldBlock { + // return Err(io::Error::new(e.kind(), e.to_string())); + // } events.clear(); poller.wait(&mut events, None)?; @@ -26,16 +25,16 @@ fn main() -> io::Result<()> { let event = events.iter().next(); if event.is_none() { println!("no event"); - break; + // break; } let event = event.unwrap(); println!("event: {:?}", event); if event.is_connect_failed() { println!("connect failed"); - break; + // break; } - } + // } Ok(()) } diff --git a/src/epoll.rs b/src/epoll.rs index 606dd1c..66067be 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -365,6 +365,11 @@ impl EventExtra { pub fn is_pri(&self) -> bool { self.flags.contains(epoll::EventFlags::PRI) } + + #[inline] + pub fn is_connect_failed(&self) -> bool { + self.flags.contains(epoll::EventFlags::ERR) && self.flags.contains(epoll::EventFlags::HUP) + } } /// The notifier for Linux. diff --git a/src/lib.rs b/src/lib.rs index 1870e63..e0e78f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -334,7 +334,10 @@ impl Event { /// Tell if this event is the result of a connect failure. /// - /// This indicates that a non-blocking connect operation has failed. + /// This indicates a tcp connection has failed, it corresponds to the `EPOLLERR` along with `EPOLLHUP` event in linux + /// and `CONNECT_FAILED` event in windows IOCP. + /// + #[inline] pub fn is_connect_failed(&self) -> bool { self.extra.is_connect_failed() From 920ed83bf4ea31802b8df73a3274c5010564d20e Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:19:08 -0500 Subject: [PATCH 03/14] update example update example --- examples/tcp_client.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index aa9d708..7637638 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -11,30 +11,23 @@ fn main() -> io::Result<()> { } let addr = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 8080); socket.set_nonblocking(true)?; - let res = socket.connect(&addr.into()); + let _ = socket.connect(&addr.into()); let mut events = polling::Events::new(); - // while let Err(ref e) = res { - // if e.kind() != io::ErrorKind::WouldBlock { - // return Err(io::Error::new(e.kind(), e.to_string())); - // } - events.clear(); - poller.wait(&mut events, None)?; + events.clear(); + poller.wait(&mut events, None)?; - let event = events.iter().next(); - if event.is_none() { - println!("no event"); - // break; - } + let event = events.iter().next(); + let Some(event) = event else { + println!("no event"); + return Ok(()); + }; - let event = event.unwrap(); - println!("event: {:?}", event); - if event.is_connect_failed() { - println!("connect failed"); - // break; - } - // } + println!("event: {:?}", event); + if event.is_connect_failed() { + println!("connect failed"); + } Ok(()) } From dea4289d61035e16143227cf388cc5481fff1c8d Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:20:25 -0500 Subject: [PATCH 04/14] ci fmt --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e0e78f6..71dd769 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -333,10 +333,10 @@ impl Event { } /// Tell if this event is the result of a connect failure. - /// + /// /// This indicates a tcp connection has failed, it corresponds to the `EPOLLERR` along with `EPOLLHUP` event in linux /// and `CONNECT_FAILED` event in windows IOCP. - /// + /// #[inline] pub fn is_connect_failed(&self) -> bool { From 903db6651d9a4efb0fa41b1101765c5020185c66 Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:24:17 -0500 Subject: [PATCH 05/14] ci, kqueue --- src/kqueue.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kqueue.rs b/src/kqueue.rs index 359305b..c349465 100644 --- a/src/kqueue.rs +++ b/src/kqueue.rs @@ -371,6 +371,12 @@ impl EventExtra { pub fn is_pri(&self) -> bool { false } + + #[inline] + pub fn is_connect_failed(&self) -> bool { + unimplemented!("is connect failed is not supported on kqueue"); + } + } pub(crate) fn mode_to_flags(mode: PollMode) -> kqueue::EventFlags { From 13b09ae9ef4a15e6c7a967971cc0f50eec1d6f82 Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:26:43 -0500 Subject: [PATCH 06/14] ci, poll --- src/poll.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/poll.rs b/src/poll.rs index 2e34d76..ff49961 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -426,6 +426,13 @@ impl EventExtra { pub fn is_pri(&self) -> bool { self.flags.contains(PollFlags::PRI) } + + #[inline] + pub fn is_connect_failed(&self) -> bool { + // need reviewer's special attention, as I do not have access to a system that supports this + // this is a guess based on the documentation of `poll()` + self.flags.contains(PollFlags::ERR) + } } fn cvt_mode_as_remove(mode: PollMode) -> io::Result { From 6983e64570563af12a26c271f23df660d2c4dd1d Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:30:25 -0500 Subject: [PATCH 07/14] more ci --- src/epoll.rs | 2 +- src/poll.rs | 2 +- src/port.rs | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/epoll.rs b/src/epoll.rs index 66067be..34a584c 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -368,7 +368,7 @@ impl EventExtra { #[inline] pub fn is_connect_failed(&self) -> bool { - self.flags.contains(epoll::EventFlags::ERR) && self.flags.contains(epoll::EventFlags::HUP) + self.flags.contains(epoll::EventFlags::ERR) || self.flags.contains(epoll::EventFlags::HUP) } } diff --git a/src/poll.rs b/src/poll.rs index ff49961..e1e3255 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -431,7 +431,7 @@ impl EventExtra { pub fn is_connect_failed(&self) -> bool { // need reviewer's special attention, as I do not have access to a system that supports this // this is a guess based on the documentation of `poll()` - self.flags.contains(PollFlags::ERR) + self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP) } } diff --git a/src/port.rs b/src/port.rs index 9d843d3..0b9a63c 100644 --- a/src/port.rs +++ b/src/port.rs @@ -250,4 +250,9 @@ impl EventExtra { pub fn is_pri(&self) -> bool { self.flags.contains(PollFlags::PRI) } + + #[inline] + pub fn is_connect_failed(&self) -> bool { + self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP) + } } From 2089ce22c9d2241767bfe679130eab987df45d54 Mon Sep 17 00:00:00 2001 From: irving ou Date: Thu, 25 Jan 2024 12:31:11 -0500 Subject: [PATCH 08/14] ci, fmt --- src/kqueue.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kqueue.rs b/src/kqueue.rs index c349465..98adfc9 100644 --- a/src/kqueue.rs +++ b/src/kqueue.rs @@ -376,7 +376,6 @@ impl EventExtra { pub fn is_connect_failed(&self) -> bool { unimplemented!("is connect failed is not supported on kqueue"); } - } pub(crate) fn mode_to_flags(mode: PollMode) -> kqueue::EventFlags { From 31444043b34e065cbe843efb03806377333a02e3 Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 10:05:19 -0500 Subject: [PATCH 09/14] refractor based on review --- examples/tcp_client.rs | 5 +++- src/iocp/mod.rs | 4 ++-- src/kqueue.rs | 4 ++-- src/lib.rs | 54 ++++++++++++++++++++++++++++++++++++++---- src/poll.rs | 6 ++--- src/port.rs | 2 +- 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index 7637638..569f943 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -25,7 +25,10 @@ fn main() -> io::Result<()> { }; println!("event: {:?}", event); - if event.is_connect_failed() { + if event + .is_connect_failed() + .expect("is connect failed does not support on this platform") + { println!("connect failed"); } diff --git a/src/iocp/mod.rs b/src/iocp/mod.rs index 1f37062..ce56ac4 100644 --- a/src/iocp/mod.rs +++ b/src/iocp/mod.rs @@ -684,8 +684,8 @@ impl EventExtra { /// Check if TCP connect failed. #[inline] - pub fn is_connect_failed(&self) -> bool { - self.flags.intersects(AfdPollMask::CONNECT_FAIL) + pub fn is_connect_failed(&self) -> Option { + Some(self.flags.intersects(AfdPollMask::CONNECT_FAIL)) } } diff --git a/src/kqueue.rs b/src/kqueue.rs index 98adfc9..3e0b044 100644 --- a/src/kqueue.rs +++ b/src/kqueue.rs @@ -373,8 +373,8 @@ impl EventExtra { } #[inline] - pub fn is_connect_failed(&self) -> bool { - unimplemented!("is connect failed is not supported on kqueue"); + pub fn is_connect_failed(&self) -> Option { + None } } diff --git a/src/lib.rs b/src/lib.rs index 71dd769..e84ed36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,14 +332,58 @@ impl Event { self.extra.is_pri() } - /// Tell if this event is the result of a connect failure. + /// Tells if this event is the result of a connection failure. /// - /// This indicates a tcp connection has failed, it corresponds to the `EPOLLERR` along with `EPOLLHUP` event in linux - /// and `CONNECT_FAILED` event in windows IOCP. + /// 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 Some(event) = event else { + /// println!("no event"); + /// return Ok(()); + /// }; + /// + /// println!("event: {:?}", event); + /// if event + /// .is_connect_failed() + /// .expect("is connect failed does not support on this platform") + /// { + /// 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] - pub fn is_connect_failed(&self) -> bool { + pub fn is_connect_failed(&self) -> Option { self.extra.is_connect_failed() } diff --git a/src/poll.rs b/src/poll.rs index e1e3255..b03e410 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -428,10 +428,8 @@ impl EventExtra { } #[inline] - pub fn is_connect_failed(&self) -> bool { - // need reviewer's special attention, as I do not have access to a system that supports this - // this is a guess based on the documentation of `poll()` - self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP) + pub fn is_connect_failed(&self) -> Option { + Some(self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP)) } } diff --git a/src/port.rs b/src/port.rs index 0b9a63c..e00fdd7 100644 --- a/src/port.rs +++ b/src/port.rs @@ -253,6 +253,6 @@ impl EventExtra { #[inline] pub fn is_connect_failed(&self) -> bool { - self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP) + Some(self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP)) } } From a00420b597074687d3e82f3b6464fb5042dde21a Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 11:22:59 -0500 Subject: [PATCH 10/14] update --- examples/tcp_client.rs | 9 ++++++--- src/lib.rs | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index 569f943..e268697 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -19,9 +19,12 @@ fn main() -> io::Result<()> { poller.wait(&mut events, None)?; let event = events.iter().next(); - let Some(event) = event else { - println!("no event"); - return Ok(()); + let event = match event { + Some(event) => event, + None => { + println!("no event"); + return Ok(()); + }, }; println!("event: {:?}", event); diff --git a/src/lib.rs b/src/lib.rs index e84ed36..eac6c93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -361,9 +361,13 @@ impl Event { /// poller.wait(&mut events, None)?; /// /// let event = events.iter().next(); - /// let Some(event) = event else { - /// println!("no event"); - /// return Ok(()); + /// + /// let event = match event { + /// Some(event) => event, + /// None => { + /// println!("no event"); + /// return Ok(()); + /// }, /// }; /// /// println!("event: {:?}", event); From 68fd1dff44ecaa4b898f2ff9b840dc02d6c2a4c1 Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 13:24:51 -0500 Subject: [PATCH 11/14] Update epoll.rs --- src/epoll.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/epoll.rs b/src/epoll.rs index 34a584c..c142f37 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -368,7 +368,7 @@ impl EventExtra { #[inline] pub fn is_connect_failed(&self) -> bool { - self.flags.contains(epoll::EventFlags::ERR) || self.flags.contains(epoll::EventFlags::HUP) + Some(self.flags.contains(epoll::EventFlags::ERR) || self.flags.contains(epoll::EventFlags::HUP)) } } From 166a14f4195a84a338fbbc9071db6c5ea57a48d6 Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 13:26:28 -0500 Subject: [PATCH 12/14] ci,fmt --- examples/tcp_client.rs | 78 +++++++++++++++++++++--------------------- src/epoll.rs | 5 ++- src/lib.rs | 2 +- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index e268697..a2c8023 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -1,39 +1,39 @@ -use std::{io, net}; - -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() - .expect("is connect failed does not support on this platform") - { - println!("connect failed"); - } - - Ok(()) -} +use std::{io, net}; + +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() + .expect("is connect failed does not support on this platform") + { + println!("connect failed"); + } + + Ok(()) +} diff --git a/src/epoll.rs b/src/epoll.rs index c142f37..0882815 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -368,7 +368,10 @@ impl EventExtra { #[inline] pub fn is_connect_failed(&self) -> bool { - Some(self.flags.contains(epoll::EventFlags::ERR) || self.flags.contains(epoll::EventFlags::HUP)) + Some( + self.flags.contains(epoll::EventFlags::ERR) + || self.flags.contains(epoll::EventFlags::HUP), + ) } } diff --git a/src/lib.rs b/src/lib.rs index eac6c93..9669771 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -361,7 +361,7 @@ impl Event { /// poller.wait(&mut events, None)?; /// /// let event = events.iter().next(); - /// + /// /// let event = match event { /// Some(event) => event, /// None => { From 621584b128107d8c1adb68c793c8e9bd744b4e7c Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 13:29:25 -0500 Subject: [PATCH 13/14] ci --- src/epoll.rs | 2 +- src/port.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/epoll.rs b/src/epoll.rs index 0882815..6edcf60 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -367,7 +367,7 @@ impl EventExtra { } #[inline] - pub fn is_connect_failed(&self) -> bool { + pub fn is_connect_failed(&self) -> Option { Some( self.flags.contains(epoll::EventFlags::ERR) || self.flags.contains(epoll::EventFlags::HUP), diff --git a/src/port.rs b/src/port.rs index e00fdd7..c88b36b 100644 --- a/src/port.rs +++ b/src/port.rs @@ -252,7 +252,7 @@ impl EventExtra { } #[inline] - pub fn is_connect_failed(&self) -> bool { + pub fn is_connect_failed(&self) -> Option { Some(self.flags.contains(PollFlags::ERR) || self.flags.contains(PollFlags::HUP)) } } From 159ab1b540b75a86f7735bcb57449b4b766e49cf Mon Sep 17 00:00:00 2001 From: irving ou Date: Fri, 26 Jan 2024 13:34:01 -0500 Subject: [PATCH 14/14] ci, doc test --- examples/tcp_client.rs | 5 +---- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index a2c8023..413f6b6 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -28,10 +28,7 @@ fn main() -> io::Result<()> { }; println!("event: {:?}", event); - if event - .is_connect_failed() - .expect("is connect failed does not support on this platform") - { + if event.is_connect_failed().unwrap_or_default() { println!("connect failed"); } diff --git a/src/lib.rs b/src/lib.rs index 9669771..9c828a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,7 +373,7 @@ impl Event { /// println!("event: {:?}", event); /// if event /// .is_connect_failed() - /// .expect("is connect failed does not support on this platform") + /// .unwrap_or_default() /// { /// println!("connect failed"); /// }