#socket

lazy-socket

Low level Raw Socket API. WIP

12 releases

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

#8 in #socket

Download history 5/week @ 2018-09-18 14/week @ 2018-09-25 48/week @ 2018-10-02 4/week @ 2018-10-09 146/week @ 2018-10-16 13/week @ 2018-10-23 2/week @ 2018-10-30 72/week @ 2018-11-06 26/week @ 2018-11-13 30/week @ 2018-11-20 26/week @ 2018-11-27 37/week @ 2018-12-04

58 downloads per month
Used in 1 crate

MIT license

47KB
965 lines

lazy-socket

Build status Build Status Crates.io Docs.rs

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

~640KB

  • unix libc 0.2.22
  • windows winapi 0.3+minwindef+handleapi+winsock2+ws2def+winerror+ntdef+inaddr+in6addr+ws2ipdef
  • bitflags 0.8