blob: 436eae5b5387e276c5a312e97a8f60c907d20dbe [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Utilities for creating and using sockets."><meta name="keywords" content="rust, rustlang, rust-lang, socket2"><title>socket2 - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../socket2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../socket2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate socket2</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.4.9</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">socket2</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/socket2/lib.rs.html#9-475">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Utilities for creating and using sockets.</p>
<p>The goal of this crate is to create and use a socket using advanced
configuration options (those that are not available in the types in the
standard library) without using any unsafe code.</p>
<p>This crate provides as direct as possible access to the system’s
functionality for sockets, this means little effort to provide
cross-platform utilities. It is up to the user to know how to use sockets
when using this crate. <em>If you don’t know how to create a socket using
libc/system calls then this crate is not for you</em>. Most, if not all,
functions directly relate to the equivalent system call with no error
handling applied, so no handling errors such as <a href="std::io::ErrorKind::Interrupted"><code>EINTR</code></a>. As a result using
this crate can be a little wordy, but it should give you maximal flexibility
over configuration of sockets.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::net::{SocketAddr, TcpListener};
<span class="kw">use </span>socket2::{Socket, Domain, Type};
<span class="comment">// Create a TCP listener bound to two addresses.
</span><span class="kw">let </span>socket = Socket::new(Domain::IPV6, Type::STREAM, <span class="prelude-val">None</span>)<span class="question-mark">?</span>;
socket.set_only_v6(<span class="bool-val">false</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>address: SocketAddr = <span class="string">&quot;[::1]:12345&quot;</span>.parse().unwrap();
socket.bind(<span class="kw-2">&amp;</span>address.into())<span class="question-mark">?</span>;
socket.listen(<span class="number">128</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>listener: TcpListener = socket.into();
<span class="comment">// ...</span></code></pre></div>
<h3 id="features"><a href="#features">Features</a></h3>
<p>This crate has a single feature <code>all</code>, which enables all functions even ones
that are not available on all OSs.</p>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Domain.html" title="socket2::Domain struct">Domain</a></div><div class="item-right docblock-short">Specification of the communication domain for a socket.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.MaybeUninitSlice.html" title="socket2::MaybeUninitSlice struct">MaybeUninitSlice</a></div><div class="item-right docblock-short">A version of <a href="std::io::IoSliceMut"><code>IoSliceMut</code></a> that allows the buffer to be uninitialised.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Protocol.html" title="socket2::Protocol struct">Protocol</a></div><div class="item-right docblock-short">Protocol specification used for creating sockets via <code>Socket::new</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.RecvFlags.html" title="socket2::RecvFlags struct">RecvFlags</a></div><div class="item-right docblock-short">Flags for incoming messages.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SockAddr.html" title="socket2::SockAddr struct">SockAddr</a></div><div class="item-right docblock-short">The address of a socket.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SockRef.html" title="socket2::SockRef struct">SockRef</a></div><div class="item-right docblock-short">A reference to a <a href="struct.Socket.html" title="Socket"><code>Socket</code></a> that can be used to configure socket types other
than the <code>Socket</code> type itself.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Socket.html" title="socket2::Socket struct">Socket</a></div><div class="item-right docblock-short">Owned wrapper around a system socket.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.TcpKeepalive.html" title="socket2::TcpKeepalive struct">TcpKeepalive</a></div><div class="item-right docblock-short">Configures a socket’s TCP keepalive parameters.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Type.html" title="socket2::Type struct">Type</a></div><div class="item-right docblock-short">Specification of communication semantics on a socket.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.InterfaceIndexOrAddress.html" title="socket2::InterfaceIndexOrAddress enum">InterfaceIndexOrAddress</a></div><div class="item-right docblock-short">A local interface specified by its index or an address assigned to it.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="socket2" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>