-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68fd1df
commit 166a14f
Showing
3 changed files
with
44 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters