Skip to content

Commit

Permalink
ci,fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingoujAtDevolution committed Jan 26, 2024
1 parent 68fd1df commit 166a14f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
78 changes: 39 additions & 39 deletions examples/tcp_client.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
5 changes: 4 additions & 1 deletion src/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl Event {
/// poller.wait(&mut events, None)?;
///
/// let event = events.iter().next();
///
///
/// let event = match event {
/// Some(event) => event,
/// None => {
Expand Down

0 comments on commit 166a14f

Please sign in to comment.