31 lines
9.1 KiB
HTML
31 lines
9.1 KiB
HTML
<!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."><title>socket2 - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="socket2" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">Crate socket2</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../socket2/index.html">socket2</a><span class="version">0.6.2</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a><ul><li><a href="#features" title="Features">Features</a></li></ul></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>socket2</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/socket2/lib.rs.html#9-705">Source</a> </span></div><details class="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="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.Interrupted" title="variant std::io::error::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 class="doc-anchor" href="#examples">§</a>Examples</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">"[::1]:12345"</span>.parse().unwrap();
|
||
socket.bind(<span class="kw-2">&</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 class="doc-anchor" href="#features">§</a>Features</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="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.CcidEndpoints.html" title="struct socket2::CcidEndpoints">Ccid<wbr>Endpoints</a></dt><dd>See <a href="struct.Socket.html#method.dccp_available_ccids" title="method socket2::Socket::dccp_available_ccids"><code>Socket::dccp_available_ccids</code></a>.</dd><dt><a class="struct" href="struct.Domain.html" title="struct socket2::Domain">Domain</a></dt><dd>Specification of the communication domain for a socket.</dd><dt><a class="struct" href="struct.MaybeUninitSlice.html" title="struct socket2::MaybeUninitSlice">Maybe<wbr>Uninit<wbr>Slice</a></dt><dd>A version of <a href="https://doc.rust-lang.org/1.93.1/std/io/struct.IoSliceMut.html" title="struct std::io::IoSliceMut"><code>IoSliceMut</code></a> that allows the buffer to be uninitialised.</dd><dt><a class="struct" href="struct.MsgHdr.html" title="struct socket2::MsgHdr">MsgHdr</a></dt><dd>Configuration of a <code>sendmsg(2)</code> system call.</dd><dt><a class="struct" href="struct.MsgHdrMut.html" title="struct socket2::MsgHdrMut">MsgHdr<wbr>Mut</a></dt><dd>Configuration of a <code>recvmsg(2)</code> system call.</dd><dt><a class="struct" href="struct.Protocol.html" title="struct socket2::Protocol">Protocol</a></dt><dd>Protocol specification used for creating sockets via <code>Socket::new</code>.</dd><dt><a class="struct" href="struct.RecvFlags.html" title="struct socket2::RecvFlags">Recv<wbr>Flags</a></dt><dd>Flags for incoming messages.</dd><dt><a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">Sock<wbr>Addr</a></dt><dd>The address of a socket.</dd><dt><a class="struct" href="struct.SockAddrStorage.html" title="struct socket2::SockAddrStorage">Sock<wbr>Addr<wbr>Storage</a></dt><dd>Rust version of the <a href="../libc/unix/linux_like/struct.sockaddr_storage.html" title="struct libc::unix::linux_like::sockaddr_storage"><code>sockaddr_storage</code></a> type.</dd><dt><a class="struct" href="struct.SockFilter.html" title="struct socket2::SockFilter">Sock<wbr>Filter</a></dt><dd>Berkeley Packet Filter (BPF).</dd><dt><a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a></dt><dd>A reference to a <a href="struct.Socket.html" title="struct socket2::Socket"><code>Socket</code></a> that can be used to configure socket types other
|
||
than the <code>Socket</code> type itself.</dd><dt><a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a></dt><dd>Owned wrapper around a system socket.</dd><dt><a class="struct" href="struct.TcpKeepalive.html" title="struct socket2::TcpKeepalive">TcpKeepalive</a></dt><dd>Configures a socket’s TCP keepalive parameters.</dd><dt><a class="struct" href="struct.Type.html" title="struct socket2::Type">Type</a></dt><dd>Specification of communication semantics on a socket.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.InterfaceIndexOrAddress.html" title="enum socket2::InterfaceIndexOrAddress">Interface<wbr>Index<wbr>OrAddress</a></dt><dd>A local interface specified by its index or an address assigned to it.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.sa_family_t.html" title="type socket2::sa_family_t">sa_<wbr>family_<wbr>t</a></dt><dd>The integer type for the <code>ss_family</code> field on this platform.</dd><dt><a class="type" href="type.socklen_t.html" title="type socket2::socklen_t">socklen_<wbr>t</a></dt><dd>The integer type used with <code>getsockname</code> on this platform.</dd></dl></section></div></main></body></html> |