11 releases
Uses old Rust 2015
0.3.0 | Feb 19, 2018 |
---|---|
0.2.2 | Feb 19, 2018 |
0.2.1 | Apr 30, 2017 |
0.2.0 | Mar 19, 2017 |
0.0.4 | Jan 31, 2017 |
#12 in #raw-sockets
51 downloads per month
Used in toa-ping
48KB
963 lines
lazy-socket
The library serves as thin wrapper over socket API. It provides necessary minimum amount of safety and easy to use.
Obsolete kinda
It seems I wouldn't need this library anymore as there is socket2 by alexcrichton.
He is definitely more trustworthy and my library might as well be forgotten. So go socket2 instead.
Examples
Create TCP socket and connect in non-blocking mode.
extern crate lazy_socket;
use std::net;
use std::str::FromStr;
use lazy_socket::raw::{
Socket,
Family,
Protocol,
Type,
select
};
fn main() {
let timeout = 1000;
let socket = match Socket::new(Family::IPv4, Type::STREAM, Protocol::TCP) {
Ok(socket) => socket,
Err(error) => {
println!("Couldn't open socket. Erro: {}", error);
return;
}
};
let dest = net::SocketAddr::from_str("192.168.0.1:80").unwrap();
let _ = socket.set_blocking(false);
let _ = socket.connect(&dest);
match select(&[], &[&socket], &[&socket], Some(timeout)) {
Ok(_) => println!("Connected!"),
Err(error) => println!("Failed to connect. Error:{}", error)
}
}
Dependencies
~140–355KB