Crate socket2 [] [src]

Utilities for handling sockets

This crate is sort of an evolution of the net2 crate after seeing the issues on it over time. The intention of this crate is to provide as direct as possible access to the system's functionality for sockets as possible. No extra fluff (e.g. multiple syscalls or builders) provided in this crate. As a result using this crate can be a little wordy, but it should give you maximal flexibility over configuration of sockets.

Examples

use socket2::{Socket, Domain, Type};

// create a TCP listener bound to two addresses
let socket = Socket::new(Domain::ipv4(), Type::stream(), None).unwrap();

socket.bind(&"127.0.0.1:12345".parse().unwrap()).unwrap();
socket.bind(&"127.0.0.1:12346".parse().unwrap()).unwrap();
socket.listen(128).unwrap();

let listener = socket.into_tcp_listener();
// ...

Structs

Domain

Specification of the communication domain for a socket.

Protocol

Protocol specification used for creating sockets via Socket::new.

Socket

Newtype, owned, wrapper around a system socket.

Type

Specification of communication semantics on a socket.