blob: dd128c4ca250264ea149e2c5f73bed7ee2ff5895 [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="A reference to a [`Socket`] that can be used to configure socket types other than the `Socket` type itself."><meta name="keywords" content="rust, rustlang, rust-lang, SockRef"><title>SockRef in 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="sidebar-items.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 struct"><!--[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="#">SockRef</a></h2><div class="sidebar-elems"><section><h3><a href="#deref-methods-Socket">Methods from Deref&lt;Target=Socket&gt;</a></h3><ul class="block"><li><a href="#method.accept">accept</a></li><li><a href="#method.accept4">accept4</a></li><li><a href="#method.accept_raw">accept_raw</a></li><li><a href="#method.attach_filter">attach_filter</a></li><li><a href="#method.bind">bind</a></li><li><a href="#method.bind_device">bind_device</a></li><li><a href="#method.broadcast">broadcast</a></li><li><a href="#method.connect">connect</a></li><li><a href="#method.connect_timeout">connect_timeout</a></li><li><a href="#method.cork">cork</a></li><li><a href="#method.cpu_affinity">cpu_affinity</a></li><li><a href="#method.detach_filter">detach_filter</a></li><li><a href="#method.device">device</a></li><li><a href="#method.domain">domain</a></li><li><a href="#method.freebind">freebind</a></li><li><a href="#method.freebind_ipv6">freebind_ipv6</a></li><li><a href="#method.header_included">header_included</a></li><li><a href="#method.ip_transparent">ip_transparent</a></li><li><a href="#method.is_listener">is_listener</a></li><li><a href="#method.join_multicast_v4">join_multicast_v4</a></li><li><a href="#method.join_multicast_v4_n">join_multicast_v4_n</a></li><li><a href="#method.join_multicast_v6">join_multicast_v6</a></li><li><a href="#method.join_ssm_v4">join_ssm_v4</a></li><li><a href="#method.keepalive">keepalive</a></li><li><a href="#method.keepalive_interval">keepalive_interval</a></li><li><a href="#method.keepalive_retries">keepalive_retries</a></li><li><a href="#method.keepalive_time">keepalive_time</a></li><li><a href="#method.leave_multicast_v4">leave_multicast_v4</a></li><li><a href="#method.leave_multicast_v4_n">leave_multicast_v4_n</a></li><li><a href="#method.leave_multicast_v6">leave_multicast_v6</a></li><li><a href="#method.leave_ssm_v4">leave_ssm_v4</a></li><li><a href="#method.linger">linger</a></li><li><a href="#method.listen">listen</a></li><li><a href="#method.local_addr">local_addr</a></li><li><a href="#method.mark">mark</a></li><li><a href="#method.mss">mss</a></li><li><a href="#method.multicast_hops_v6">multicast_hops_v6</a></li><li><a href="#method.multicast_if_v4">multicast_if_v4</a></li><li><a href="#method.multicast_if_v6">multicast_if_v6</a></li><li><a href="#method.multicast_loop_v4">multicast_loop_v4</a></li><li><a href="#method.multicast_loop_v6">multicast_loop_v6</a></li><li><a href="#method.multicast_ttl_v4">multicast_ttl_v4</a></li><li><a href="#method.nodelay">nodelay</a></li><li><a href="#method.only_v6">only_v6</a></li><li><a href="#method.out_of_band_inline">out_of_band_inline</a></li><li><a href="#method.peek">peek</a></li><li><a href="#method.peek_from">peek_from</a></li><li><a href="#method.peek_sender">peek_sender</a></li><li><a href="#method.peer_addr">peer_addr</a></li><li><a href="#method.protocol">protocol</a></li><li><a href="#method.quickack">quickack</a></li><li><a href="#method.read_timeout">read_timeout</a></li><li><a href="#method.recv">recv</a></li><li><a href="#method.recv_buffer_size">recv_buffer_size</a></li><li><a href="#method.recv_from">recv_from</a></li><li><a href="#method.recv_from_vectored">recv_from_vectored</a></li><li><a href="#method.recv_from_vectored_with_flags">recv_from_vectored_with_flags</a></li><li><a href="#method.recv_from_with_flags">recv_from_with_flags</a></li><li><a href="#method.recv_out_of_band">recv_out_of_band</a></li><li><a href="#method.recv_tos">recv_tos</a></li><li><a href="#method.recv_vectored">recv_vectored</a></li><li><a href="#method.recv_vectored_with_flags">recv_vectored_with_flags</a></li><li><a href="#method.recv_with_flags">recv_with_flags</a></li><li><a href="#method.reuse_address">reuse_address</a></li><li><a href="#method.reuse_port">reuse_port</a></li><li><a href="#method.send">send</a></li><li><a href="#method.send_buffer_size">send_buffer_size</a></li><li><a href="#method.send_out_of_band">send_out_of_band</a></li><li><a href="#method.send_to">send_to</a></li><li><a href="#method.send_to_vectored">send_to_vectored</a></li><li><a href="#method.send_to_vectored_with_flags">send_to_vectored_with_flags</a></li><li><a href="#method.send_to_with_flags">send_to_with_flags</a></li><li><a href="#method.send_vectored">send_vectored</a></li><li><a href="#method.send_vectored_with_flags">send_vectored_with_flags</a></li><li><a href="#method.send_with_flags">send_with_flags</a></li><li><a href="#method.sendfile">sendfile</a></li><li><a href="#method.set_broadcast">set_broadcast</a></li><li><a href="#method.set_cloexec">set_cloexec</a></li><li><a href="#method.set_cork">set_cork</a></li><li><a href="#method.set_cpu_affinity">set_cpu_affinity</a></li><li><a href="#method.set_freebind">set_freebind</a></li><li><a href="#method.set_freebind_ipv6">set_freebind_ipv6</a></li><li><a href="#method.set_header_included">set_header_included</a></li><li><a href="#method.set_ip_transparent">set_ip_transparent</a></li><li><a href="#method.set_keepalive">set_keepalive</a></li><li><a href="#method.set_linger">set_linger</a></li><li><a href="#method.set_mark">set_mark</a></li><li><a href="#method.set_mss">set_mss</a></li><li><a href="#method.set_multicast_hops_v6">set_multicast_hops_v6</a></li><li><a href="#method.set_multicast_if_v4">set_multicast_if_v4</a></li><li><a href="#method.set_multicast_if_v6">set_multicast_if_v6</a></li><li><a href="#method.set_multicast_loop_v4">set_multicast_loop_v4</a></li><li><a href="#method.set_multicast_loop_v6">set_multicast_loop_v6</a></li><li><a href="#method.set_multicast_ttl_v4">set_multicast_ttl_v4</a></li><li><a href="#method.set_nodelay">set_nodelay</a></li><li><a href="#method.set_nonblocking">set_nonblocking</a></li><li><a href="#method.set_nosigpipe">set_nosigpipe</a></li><li><a href="#method.set_only_v6">set_only_v6</a></li><li><a href="#method.set_out_of_band_inline">set_out_of_band_inline</a></li><li><a href="#method.set_quickack">set_quickack</a></li><li><a href="#method.set_read_timeout">set_read_timeout</a></li><li><a href="#method.set_recv_buffer_size">set_recv_buffer_size</a></li><li><a href="#method.set_recv_tos">set_recv_tos</a></li><li><a href="#method.set_reuse_address">set_reuse_address</a></li><li><a href="#method.set_reuse_port">set_reuse_port</a></li><li><a href="#method.set_send_buffer_size">set_send_buffer_size</a></li><li><a href="#method.set_tcp_keepalive">set_tcp_keepalive</a></li><li><a href="#method.set_tcp_user_timeout">set_tcp_user_timeout</a></li><li><a href="#method.set_thin_linear_timeouts">set_thin_linear_timeouts</a></li><li><a href="#method.set_tos">set_tos</a></li><li><a href="#method.set_ttl">set_ttl</a></li><li><a href="#method.set_unicast_hops_v6">set_unicast_hops_v6</a></li><li><a href="#method.set_write_timeout">set_write_timeout</a></li><li><a href="#method.shutdown">shutdown</a></li><li><a href="#method.take_error">take_error</a></li><li><a href="#method.tcp_user_timeout">tcp_user_timeout</a></li><li><a href="#method.thin_linear_timeouts">thin_linear_timeouts</a></li><li><a href="#method.tos">tos</a></li><li><a href="#method.try_clone">try_clone</a></li><li><a href="#method.ttl">ttl</a></li><li><a href="#method.type">type</a></li><li><a href="#method.unicast_hops_v6">unicast_hops_v6</a></li><li><a href="#method.write_timeout">write_timeout</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Debug-for-SockRef%3C%27_%3E">Debug</a></li><li><a href="#impl-Deref-for-SockRef%3C%27s%3E">Deref</a></li><li><a href="#impl-From%3C%26%27s%20S%3E-for-SockRef%3C%27s%3E">From&lt;&amp;&#39;s S&gt;</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-SockRef%3C%27s%3E">RefUnwindSafe</a></li><li><a href="#impl-Send-for-SockRef%3C%27s%3E">Send</a></li><li><a href="#impl-Sync-for-SockRef%3C%27s%3E">Sync</a></li><li><a href="#impl-Unpin-for-SockRef%3C%27s%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-SockRef%3C%27s%3E">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-SockRef%3C%27s%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-SockRef%3C%27s%3E">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-SockRef%3C%27s%3E">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-SockRef%3C%27s%3E">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-SockRef%3C%27s%3E">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-SockRef%3C%27s%3E">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-SockRef%3C%27s%3E">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In socket2</a></h2></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">Struct <a href="index.html">socket2</a>::<wbr><a class="struct" href="#">SockRef</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/sockref.rs.html#85-93">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct SockRef&lt;'s&gt; { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>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.</p>
<p>This allows for example a <a href="std::net::TcpStream"><code>TcpStream</code></a>, found in the standard library, to
be configured using all the additional methods found in the <a href="struct.Socket.html" title="Socket"><code>Socket</code></a> API.</p>
<p><code>SockRef</code> can be created from any socket type that implements <a href="https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsRawFd.html"><code>AsRawFd</code></a>
(Unix) or <a href="https://doc.rust-lang.org/stable/std/os/windows/io/trait.AsRawSocket.html"><code>AsRawSocket</code></a> (Windows) using the [<code>From</code>] implementation, but
the caller must ensure the file descriptor/socket is a valid.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<p>Below is an example of converting a <a href="std::net::TcpStream"><code>TcpStream</code></a> into a <a href="struct.SockRef.html" title="SockRef"><code>SockRef</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::net::{TcpStream, SocketAddr};
<span class="kw">use </span>socket2::SockRef;
<span class="comment">// Create `TcpStream` from the standard library.
</span><span class="kw">let </span>address: SocketAddr = <span class="string">&quot;127.0.0.1:1234&quot;</span>.parse()<span class="question-mark">?</span>;
<span class="kw">let </span>stream = TcpStream::connect(address)<span class="question-mark">?</span>;
<span class="comment">// Create a `SockRef`erence to the stream.
</span><span class="kw">let </span>socket_ref = SockRef::from(<span class="kw-2">&amp;</span>stream);
<span class="comment">// Use `Socket::set_nodelay` on the stream.
</span>socket_ref.set_nodelay(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
drop(socket_ref);
<span class="macro">assert_eq!</span>(stream.nodelay()<span class="question-mark">?</span>, <span class="bool-val">true</span>);</code></pre></div>
<p>Below is an example of <strong>incorrect usage</strong> of <code>SockRef::from</code>, which is
currently possible (but not intended and will be fixed in future versions).</p>
<div class="example-wrap compile_fail"><div class='tooltip'></div><pre class="rust rust-example-rendered"><code><span class="kw">use </span>socket2::SockRef;
<span class="doccomment">/// THIS USAGE IS NOT VALID!
</span><span class="kw">let </span>socket_ref = SockRef::from(<span class="kw-2">&amp;</span><span class="number">123</span>);
<span class="comment">// The above line is overseen possibility when using `SockRef::from`, it
// uses the `RawFd` (on Unix), which is a type alias for `c_int`/`i32`,
// which implements `AsRawFd`. However it may be clear that this usage is
// invalid as it doesn&#39;t guarantee that `123` is a valid file descriptor.
// Using `Socket::set_nodelay` now will call it on a file descriptor we
// don&#39;t own! We don&#39;t even not if the file descriptor is valid or a socket.
</span>socket_ref.set_nodelay(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
drop(socket_ref);</code></pre></div>
</div></details><h2 id="deref-methods-Socket" class="small-section-header"><span>Methods from Deref&lt;Target = <a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a>&gt;</span><a href="#deref-methods-Socket" class="anchor"></a></h2><div id="deref-methods-Socket-1"><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.bind" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#182-184">source</a><h4 class="code-header">pub fn <a href="#method.bind" class="fnname">bind</a>(&amp;self, address: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Binds this socket to the specified address.</p>
<p>This function directly corresponds to the <code>bind(2)</code> function on Windows
and Unix.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#200-202">source</a><h4 class="code-header">pub fn <a href="#method.connect" class="fnname">connect</a>(&amp;self, address: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Initiate a connection on this socket to the specified address.</p>
<p>This function directly corresponds to the <code>connect(2)</code> function on
Windows and Unix.</p>
<p>An error will be returned if <code>listen</code> or <code>connect</code> has already been
called on this builder.</p>
<h5 id="notes"><a href="#notes">Notes</a></h5>
<p>When using a non-blocking connect (by setting the socket into
non-blocking mode before calling this function), socket option can’t be
set <em>while connecting</em>. This will cause errors on Windows. Socket
options can be safely set before and after connecting the socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#223-237">source</a><h4 class="code-header">pub fn <a href="#method.connect_timeout" class="fnname">connect_timeout</a>(&amp;self, addr: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>, timeout: Duration) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Initiate a connection on this socket to the specified address, only
only waiting for a certain period of time for the connection to be
established.</p>
<p>Unlike many other methods on <code>Socket</code>, this does <em>not</em> correspond to a
single C function. It sets the socket to nonblocking mode, connects via
connect(2), and then waits for the connection to complete with poll(2)
on Unix and select on Windows. When the connection is complete, the
socket is set back to blocking mode. On Unix, this will loop over
<code>EINTR</code> errors.</p>
<h5 id="warnings"><a href="#warnings">Warnings</a></h5>
<p>The non-blocking state of the socket is overridden by this function -
it will be returned in blocking mode on success, and in an indeterminate
state on failure.</p>
<p>If the connection request times out, it may still be processing in the
background - a second call to <code>connect</code> or <code>connect_timeout</code> may fail.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.listen" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#247-249">source</a><h4 class="code-header">pub fn <a href="#method.listen" class="fnname">listen</a>(&amp;self, backlog: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Mark a socket as ready to accept incoming connection requests using
<a href="struct.Socket.html#method.accept" title="Socket::accept()"><code>Socket::accept()</code></a>.</p>
<p>This function directly corresponds to the <code>listen(2)</code> function on
Windows and Unix.</p>
<p>An error will be returned if <code>listen</code> or <code>connect</code> has already been
called on this builder.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.accept" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#258-292">source</a><h4 class="code-header">pub fn <a href="#method.accept" class="fnname">accept</a>(&amp;self) -&gt; Result&lt;(<a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a>, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Accept a new incoming connection from this listener.</p>
<p>This function uses <code>accept4(2)</code> on platforms that support it and
<code>accept(2)</code> platforms that do not.</p>
<p>This function sets the same flags as in done for <a href="struct.Socket.html#method.new" title="Socket::new"><code>Socket::new</code></a>,
<a href="struct.Socket.html#method.accept_raw" title="Socket::accept_raw"><code>Socket::accept_raw</code></a> can be used if you don’t want to set those flags.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.accept_raw" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#298-300">source</a><h4 class="code-header">pub fn <a href="#method.accept_raw" class="fnname">accept_raw</a>(&amp;self) -&gt; Result&lt;(<a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a>, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Accept a new incoming connection from this listener.</p>
<p>This function directly corresponds to the <code>accept(2)</code> function on
Windows and Unix.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.local_addr" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#310-312">source</a><h4 class="code-header">pub fn <a href="#method.local_addr" class="fnname">local_addr</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address of the local half of this socket.</p>
<h5 id="notes-1"><a href="#notes-1">Notes</a></h5>
<p>Depending on the OS this may return an error if the socket is not
<a href="struct.Socket.html#method.bind">bound</a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peer_addr" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#321-323">source</a><h4 class="code-header">pub fn <a href="#method.peer_addr" class="fnname">peer_addr</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address of the remote peer of this socket.</p>
<h5 id="notes-2"><a href="#notes-2">Notes</a></h5>
<p>This returns an error if the socket is not <a href="struct.Socket.html#method.connect"><code>connect</code>ed</a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#327-329">source</a><h4 class="code-header">pub fn <a href="#method.type" class="fnname">type</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.Type.html" title="struct socket2::Type">Type</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the <a href="struct.Type.html" title="Type"><code>Type</code></a> of this socket by checking the <code>SO_TYPE</code> option on
this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_clone" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#344-346">source</a><h4 class="code-header">pub fn <a href="#method.try_clone" class="fnname">try_clone</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a new independently owned handle to the underlying socket.</p>
<h5 id="notes-3"><a href="#notes-3">Notes</a></h5>
<p>On Unix this uses <code>F_DUPFD_CLOEXEC</code> and thus sets the <code>FD_CLOEXEC</code> on
the returned socket.</p>
<p>On Windows this uses <code>WSA_FLAG_NO_HANDLE_INHERIT</code> setting inheriting to
false.</p>
<p>On Windows this can <strong>not</strong> be used function cannot be used on a
QOS-enabled socket, see
<a href="https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaduplicatesocketw">https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaduplicatesocketw</a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_nonblocking" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#356-358">source</a><h4 class="code-header">pub fn <a href="#method.set_nonblocking" class="fnname">set_nonblocking</a>(&amp;self, nonblocking: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Moves this TCP stream into or out of nonblocking mode.</p>
<h5 id="notes-4"><a href="#notes-4">Notes</a></h5>
<p>On Unix this corresponds to calling <code>fcntl</code> (un)setting <code>O_NONBLOCK</code>.</p>
<p>On Windows this corresponds to calling <code>ioctlsocket</code> (un)setting
<code>FIONBIO</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.shutdown" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#364-366">source</a><h4 class="code-header">pub fn <a href="#method.shutdown" class="fnname">shutdown</a>(&amp;self, how: Shutdown) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Shuts down the read, write, or both halves of this connection.</p>
<p>This function will cause all pending and future I/O on the specified
portions to return immediately with an appropriate value.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#388-390">source</a><h4 class="code-header">pub fn <a href="#method.recv" class="fnname">recv</a>(&amp;self, buf: &amp;mut [MaybeUninit&lt;u8&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Receives data on the socket from the remote address to which it is
connected.</p>
<p>The <a href="struct.Socket.html#method.connect"><code>connect</code></a> method will connect this socket to a remote address.
This method might fail if the socket is not connected.</p>
<h5 id="safety"><a href="#safety">Safety</a></h5>
<p>Normally casting a <code>&amp;mut [u8]</code> to <code>&amp;mut [MaybeUninit&lt;u8&gt;]</code> would be
unsound, as that allows us to write uninitialised bytes to the buffer.
However this implementation promises to not write uninitialised bytes to
the <code>buf</code>fer and passes it directly to <code>recv(2)</code> system call. This
promise ensures that this function can be called using a <code>buf</code>fer of
type <code>&amp;mut [u8]</code>.</p>
<p>Note that the [<code>io::Read::read</code>] implementation calls this function with
a <code>buf</code>fer of type <code>&amp;mut [u8]</code>, allowing initialised buffers to be used
without using <code>unsafe</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_out_of_band" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#399-401">source</a><h4 class="code-header">pub fn <a href="#method.recv_out_of_band" class="fnname">recv_out_of_band</a>(&amp;self, buf: &amp;mut [MaybeUninit&lt;u8&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Receives out-of-band (OOB) data on the socket from the remote address to
which it is connected by setting the <code>MSG_OOB</code> flag for this call.</p>
<p>For more information, see <a href="struct.Socket.html#method.recv"><code>recv</code></a>, <a href="struct.Socket.html#method.out_of_band_inline"><code>out_of_band_inline</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#407-413">source</a><h4 class="code-header">pub fn <a href="#method.recv_with_flags" class="fnname">recv_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;mut [MaybeUninit&lt;u8&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.recv"><code>recv</code></a> but allows for specification of arbitrary flags to
the underlying <code>recv</code> call.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_vectored" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#442-447">source</a><h4 class="code-header">pub fn <a href="#method.recv_vectored" class="fnname">recv_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;mut [<a class="struct" href="struct.MaybeUninitSlice.html" title="struct socket2::MaybeUninitSlice">MaybeUninitSlice</a>&lt;'_&gt;]<br>) -&gt; Result&lt;(usize, <a class="struct" href="struct.RecvFlags.html" title="struct socket2::RecvFlags">RecvFlags</a>)&gt;</h4></section></summary><div class="docblock"><p>Receives data on the socket from the remote address to which it is
connected. Unlike <a href="struct.Socket.html#method.recv"><code>recv</code></a> this allows passing multiple buffers.</p>
<p>The <a href="struct.Socket.html#method.connect"><code>connect</code></a> method will connect this socket to a remote address.
This method might fail if the socket is not connected.</p>
<p>In addition to the number of bytes read, this function returns the flags
for the received message. See <a href="struct.RecvFlags.html" title="RecvFlags"><code>RecvFlags</code></a> for more information about
the returned flags.</p>
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
<p>Normally casting a <code>IoSliceMut</code> to <code>MaybeUninitSlice</code> would be unsound,
as that allows us to write uninitialised bytes to the buffer. However
this implementation promises to not write uninitialised bytes to the
<code>bufs</code> and passes it directly to <code>recvmsg(2)</code> system call. This promise
ensures that this function can be called using <code>bufs</code> of type <code>&amp;mut [IoSliceMut]</code>.</p>
<p>Note that the [<code>io::Read::read_vectored</code>] implementation calls this
function with <code>buf</code>s of type <code>&amp;mut [IoSliceMut]</code>, allowing initialised
buffers to be used without using <code>unsafe</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_vectored_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#462-468">source</a><h4 class="code-header">pub fn <a href="#method.recv_vectored_with_flags" class="fnname">recv_vectored_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;mut [<a class="struct" href="struct.MaybeUninitSlice.html" title="struct socket2::MaybeUninitSlice">MaybeUninitSlice</a>&lt;'_&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;(usize, <a class="struct" href="struct.RecvFlags.html" title="struct socket2::RecvFlags">RecvFlags</a>)&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.recv_vectored"><code>recv_vectored</code></a> but allows for specification of arbitrary
flags to the underlying <code>recvmsg</code>/<code>WSARecv</code> call.</p>
<h5 id="safety-2"><a href="#safety-2">Safety</a></h5>
<p><code>recv_from_vectored</code> makes the same safety guarantees regarding <code>bufs</code>
as <a href="struct.Socket.html#method.recv_vectored"><code>recv_vectored</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peek" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#483-485">source</a><h4 class="code-header">pub fn <a href="#method.peek" class="fnname">peek</a>(&amp;self, buf: &amp;mut [MaybeUninit&lt;u8&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Receives data on the socket from the remote adress to which it is
connected, without removing that data from the queue. On success,
returns the number of bytes peeked.</p>
<p>Successive calls return the same data. This is accomplished by passing
<code>MSG_PEEK</code> as a flag to the underlying <code>recv</code> system call.</p>
<h5 id="safety-3"><a href="#safety-3">Safety</a></h5>
<p><code>peek</code> makes the same safety guarantees regarding the <code>buf</code>fer as
<a href="struct.Socket.html#method.recv"><code>recv</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_from" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#496-498">source</a><h4 class="code-header">pub fn <a href="#method.recv_from" class="fnname">recv_from</a>(&amp;self, buf: &amp;mut [MaybeUninit&lt;u8&gt;]) -&gt; Result&lt;(usize, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket. On success, returns the number of bytes
read and the address from whence the data came.</p>
<h5 id="safety-4"><a href="#safety-4">Safety</a></h5>
<p><code>recv_from</code> makes the same safety guarantees regarding the <code>buf</code>fer as
<a href="struct.Socket.html#method.recv"><code>recv</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_from_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#504-510">source</a><h4 class="code-header">pub fn <a href="#method.recv_from_with_flags" class="fnname">recv_from_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;mut [MaybeUninit&lt;u8&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;(usize, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.recv_from"><code>recv_from</code></a> but allows for specification of arbitrary
flags to the underlying <code>recvfrom</code> call.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_from_vectored" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#526-531">source</a><h4 class="code-header">pub fn <a href="#method.recv_from_vectored" class="fnname">recv_from_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;mut [<a class="struct" href="struct.MaybeUninitSlice.html" title="struct socket2::MaybeUninitSlice">MaybeUninitSlice</a>&lt;'_&gt;]<br>) -&gt; Result&lt;(usize, <a class="struct" href="struct.RecvFlags.html" title="struct socket2::RecvFlags">RecvFlags</a>, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket. Returns the amount of bytes read, the
<a href="struct.RecvFlags.html" title="RecvFlags"><code>RecvFlags</code></a> and the remote address from the data is coming. Unlike
<a href="struct.Socket.html#method.recv_from"><code>recv_from</code></a> this allows passing multiple buffers.</p>
<h5 id="safety-5"><a href="#safety-5">Safety</a></h5>
<p><code>recv_from_vectored</code> makes the same safety guarantees regarding <code>bufs</code>
as <a href="struct.Socket.html#method.recv_vectored"><code>recv_vectored</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_from_vectored_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#546-552">source</a><h4 class="code-header">pub fn <a href="#method.recv_from_vectored_with_flags" class="fnname">recv_from_vectored_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;mut [<a class="struct" href="struct.MaybeUninitSlice.html" title="struct socket2::MaybeUninitSlice">MaybeUninitSlice</a>&lt;'_&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;(usize, <a class="struct" href="struct.RecvFlags.html" title="struct socket2::RecvFlags">RecvFlags</a>, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.recv_from_vectored"><code>recv_from_vectored</code></a> but allows for specification of
arbitrary flags to the underlying <code>recvmsg</code>/<code>WSARecvFrom</code> call.</p>
<h5 id="safety-6"><a href="#safety-6">Safety</a></h5>
<p><code>recv_from_vectored</code> makes the same safety guarantees regarding <code>bufs</code>
as <a href="struct.Socket.html#method.recv_vectored"><code>recv_vectored</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peek_from" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#583-585">source</a><h4 class="code-header">pub fn <a href="#method.peek_from" class="fnname">peek_from</a>(&amp;self, buf: &amp;mut [MaybeUninit&lt;u8&gt;]) -&gt; Result&lt;(usize, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket, without removing it from the queue.</p>
<p>Successive calls return the same data. This is accomplished by passing
<code>MSG_PEEK</code> as a flag to the underlying <code>recvfrom</code> system call.</p>
<p>On success, returns the number of bytes peeked and the address from
whence the data came.</p>
<h5 id="safety-7"><a href="#safety-7">Safety</a></h5>
<p><code>peek_from</code> makes the same safety guarantees regarding the <code>buf</code>fer as
<a href="struct.Socket.html#method.recv"><code>recv</code></a>.</p>
<h5 id="note-datagram-sockets"><a href="#note-datagram-sockets">Note: Datagram Sockets</a></h5>
<p>For datagram sockets, the behavior of this method when <code>buf</code> is smaller than
the datagram at the head of the receive queue differs between Windows and
Unix-like platforms (Linux, macOS, BSDs, etc: colloquially termed “*nix”).</p>
<p>On *nix platforms, the datagram is truncated to the length of <code>buf</code>.</p>
<p>On Windows, an error corresponding to <code>WSAEMSGSIZE</code> will be returned.</p>
<p>For consistency between platforms, be sure to provide a sufficiently large buffer to avoid
truncation; the exact size required depends on the underlying protocol.</p>
<p>If you just want to know the sender of the data, try <a href="struct.Socket.html#method.peek_sender"><code>peek_sender</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peek_sender" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#593-595">source</a><h4 class="code-header">pub fn <a href="#method.peek_sender" class="fnname">peek_sender</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Retrieve the sender for the data at the head of the receive queue.</p>
<p>This is equivalent to calling <a href="struct.Socket.html#method.peek_from"><code>peek_from</code></a> with a zero-sized buffer,
but suppresses the <code>WSAEMSGSIZE</code> error on Windows.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#603-605">source</a><h4 class="code-header">pub fn <a href="#method.send" class="fnname">send</a>(&amp;self, buf: &amp;[u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Sends data on the socket to a connected peer.</p>
<p>This is typically used on TCP sockets or datagram sockets which have
been connected.</p>
<p>On success returns the number of bytes that were sent.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#611-613">source</a><h4 class="code-header">pub fn <a href="#method.send_with_flags" class="fnname">send_with_flags</a>(&amp;self, buf: &amp;[u8], flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="#method.send"><code>send</code></a> but allows for specification of arbitrary flags to the underlying
<code>send</code> call.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_vectored" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#618-620">source</a><h4 class="code-header">pub fn <a href="#method.send_vectored" class="fnname">send_vectored</a>(&amp;self, bufs: &amp;[IoSlice&lt;'_&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Send data to the connected peer. Returns the amount of bytes written.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_vectored_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#628-634">source</a><h4 class="code-header">pub fn <a href="#method.send_vectored_with_flags" class="fnname">send_vectored_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;[IoSlice&lt;'_&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.send_vectored"><code>send_vectored</code></a> but allows for specification of arbitrary
flags to the underlying <code>sendmsg</code>/<code>WSASend</code> call.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_out_of_band" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#643-645">source</a><h4 class="code-header">pub fn <a href="#method.send_out_of_band" class="fnname">send_out_of_band</a>(&amp;self, buf: &amp;[u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Sends out-of-band (OOB) data on the socket to connected peer
by setting the <code>MSG_OOB</code> flag for this call.</p>
<p>For more information, see <a href="#method.send"><code>send</code></a>, <a href="#method.out_of_band_inline"><code>out_of_band_inline</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_to" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#651-653">source</a><h4 class="code-header">pub fn <a href="#method.send_to" class="fnname">send_to</a>(&amp;self, buf: &amp;[u8], addr: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Sends data on the socket to the given address. On success, returns the
number of bytes written.</p>
<p>This is typically used on UDP or datagram-oriented sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_to_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#659-666">source</a><h4 class="code-header">pub fn <a href="#method.send_to_with_flags" class="fnname">send_to_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;[u8],<br>&nbsp;&nbsp;&nbsp;&nbsp;addr: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.send_to"><code>send_to</code></a> but allows for specification of arbitrary flags
to the underlying <code>sendto</code> call.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_to_vectored" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#672-674">source</a><h4 class="code-header">pub fn <a href="#method.send_to_vectored" class="fnname">send_to_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;[IoSlice&lt;'_&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;addr: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a><br>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Send data to a peer listening on <code>addr</code>. Returns the amount of bytes
written.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_to_vectored_with_flags" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#682-689">source</a><h4 class="code-header">pub fn <a href="#method.send_to_vectored_with_flags" class="fnname">send_to_vectored_with_flags</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;[IoSlice&lt;'_&gt;],<br>&nbsp;&nbsp;&nbsp;&nbsp;addr: &amp;<a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a><br>) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Identical to <a href="struct.Socket.html#method.send_to_vectored"><code>send_to_vectored</code></a> but allows for specification of
arbitrary flags to the underlying <code>sendmsg</code>/<code>WSASendTo</code> call.</p>
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.broadcast" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#773-778">source</a><h4 class="code-header">pub fn <a href="#method.broadcast" class="fnname">broadcast</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_BROADCAST</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_broadcast"><code>set_broadcast</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_broadcast" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#784-793">source</a><h4 class="code-header">pub fn <a href="#method.set_broadcast" class="fnname">set_broadcast</a>(&amp;self, broadcast: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>SO_BROADCAST</code> option for this socket.</p>
<p>When enabled, this socket is allowed to send packets to a broadcast
address.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.take_error" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#800-806">source</a><h4 class="code-header">pub fn <a href="#method.take_error" class="fnname">take_error</a>(&amp;self) -&gt; Result&lt;Option&lt;Error&gt;&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_ERROR</code> option on this socket.</p>
<p>This will retrieve the stored error in the underlying socket, clearing
the field in the process. This can be useful for checking errors between
calls.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.keepalive" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#813-818">source</a><h4 class="code-header">pub fn <a href="#method.keepalive" class="fnname">keepalive</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_KEEPALIVE</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_keepalive"><code>set_keepalive</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_keepalive" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#823-832">source</a><h4 class="code-header">pub fn <a href="#method.set_keepalive" class="fnname">set_keepalive</a>(&amp;self, keepalive: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_KEEPALIVE</code> option on this socket.</p>
<p>Enable sending of keep-alive messages on connection-oriented sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.linger" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#839-844">source</a><h4 class="code-header">pub fn <a href="#method.linger" class="fnname">linger</a>(&amp;self) -&gt; Result&lt;Option&lt;Duration&gt;&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_LINGER</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_linger"><code>set_linger</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_linger" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#860-863">source</a><h4 class="code-header">pub fn <a href="#method.set_linger" class="fnname">set_linger</a>(&amp;self, linger: Option&lt;Duration&gt;) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_LINGER</code> option on this socket.</p>
<p>If <code>linger</code> is not <code>None</code>, a close(2) or shutdown(2) will not return
until all queued messages for the socket have been successfully sent or
the linger timeout has been reached. Otherwise, the call returns
immediately and the closing is done in the background. When the socket
is closed as part of exit(2), it always lingers in the background.</p>
<h5 id="notes-5"><a href="#notes-5">Notes</a></h5>
<p>On most OSs the duration only has a precision of seconds and will be
silently truncated.</p>
<p>On Apple platforms (e.g. macOS, iOS, etc) this uses <code>SO_LINGER_SEC</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.out_of_band_inline" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#872-877">source</a><h4 class="code-header">pub fn <a href="#method.out_of_band_inline" class="fnname">out_of_band_inline</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get value for the <code>SO_OOBINLINE</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_out_of_band_inline"><code>set_out_of_band_inline</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_out_of_band_inline" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#887-896">source</a><h4 class="code-header">pub fn <a href="#method.set_out_of_band_inline" class="fnname">set_out_of_band_inline</a>(&amp;self, oob_inline: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_OOBINLINE</code> option on this socket.</p>
<p>If this option is enabled, out-of-band data is directly placed into the
receive data stream. Otherwise, out-of-band data is passed only when the
<code>MSG_OOB</code> flag is set during receiving. As per RFC6093, TCP sockets
using the Urgent mechanism are encouraged to set this flag.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_buffer_size" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#903-908">source</a><h4 class="code-header">pub fn <a href="#method.recv_buffer_size" class="fnname">recv_buffer_size</a>(&amp;self) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Get value for the <code>SO_RCVBUF</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_recv_buffer_size"><code>set_recv_buffer_size</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_recv_buffer_size" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#914-923">source</a><h4 class="code-header">pub fn <a href="#method.set_recv_buffer_size" class="fnname">set_recv_buffer_size</a>(&amp;self, size: usize) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_RCVBUF</code> option on this socket.</p>
<p>Changes the size of the operating system’s receive buffer associated
with the socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.read_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#929-931">source</a><h4 class="code-header">pub fn <a href="#method.read_timeout" class="fnname">read_timeout</a>(&amp;self) -&gt; Result&lt;Option&lt;Duration&gt;&gt;</h4></section></summary><div class="docblock"><p>Get value for the <code>SO_RCVTIMEO</code> option on this socket.</p>
<p>If the returned timeout is <code>None</code>, then <code>read</code> and <code>recv</code> calls will
block indefinitely.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_read_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#937-939">source</a><h4 class="code-header">pub fn <a href="#method.set_read_timeout" class="fnname">set_read_timeout</a>(&amp;self, duration: Option&lt;Duration&gt;) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_RCVTIMEO</code> option on this socket.</p>
<p>If <code>timeout</code> is <code>None</code>, then <code>read</code> and <code>recv</code> calls will block
indefinitely.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.reuse_address" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#946-951">source</a><h4 class="code-header">pub fn <a href="#method.reuse_address" class="fnname">reuse_address</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_REUSEADDR</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_reuse_address"><code>set_reuse_address</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_reuse_address" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#958-967">source</a><h4 class="code-header">pub fn <a href="#method.set_reuse_address" class="fnname">set_reuse_address</a>(&amp;self, reuse: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_REUSEADDR</code> option on this socket.</p>
<p>This indicates that futher calls to <code>bind</code> may allow reuse of local
addresses. For IPv4 sockets this means that a socket may bind even when
there’s a socket already listening on this port.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_buffer_size" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#974-979">source</a><h4 class="code-header">pub fn <a href="#method.send_buffer_size" class="fnname">send_buffer_size</a>(&amp;self) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_SNDBUF</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_send_buffer_size"><code>set_send_buffer_size</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_send_buffer_size" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#985-994">source</a><h4 class="code-header">pub fn <a href="#method.set_send_buffer_size" class="fnname">set_send_buffer_size</a>(&amp;self, size: usize) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_SNDBUF</code> option on this socket.</p>
<p>Changes the size of the operating system’s send buffer associated with
the socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1000-1002">source</a><h4 class="code-header">pub fn <a href="#method.write_timeout" class="fnname">write_timeout</a>(&amp;self) -&gt; Result&lt;Option&lt;Duration&gt;&gt;</h4></section></summary><div class="docblock"><p>Get value for the <code>SO_SNDTIMEO</code> option on this socket.</p>
<p>If the returned timeout is <code>None</code>, then <code>write</code> and <code>send</code> calls will
block indefinitely.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_write_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1008-1010">source</a><h4 class="code-header">pub fn <a href="#method.set_write_timeout" class="fnname">set_write_timeout</a>(&amp;self, duration: Option&lt;Duration&gt;) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_SNDTIMEO</code> option on this socket.</p>
<p>If <code>timeout</code> is <code>None</code>, then <code>write</code> and <code>send</code> calls will block
indefinitely.</p>
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.header_included" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1047-1052">source</a><h4 class="code-header">pub fn <a href="#method.header_included" class="fnname">header_included</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_HDRINCL</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_header_included"><code>set_header_included</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_header_included" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1067-1076">source</a><h4 class="code-header">pub fn <a href="#method.set_header_included" class="fnname">set_header_included</a>(&amp;self, included: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_HDRINCL</code> option on this socket.</p>
<p>If enabled, the user supplies an IP header in front of the user data.
Valid only for <a href="struct.Type.html#associatedconstant.RAW"><code>SOCK_RAW</code></a> sockets; see <a href="https://man7.org/linux/man-pages/man7/raw.7.html">raw(7)</a> for more information.
When this flag is enabled, the values set by <code>IP_OPTIONS</code>, <a href="struct.Socket.html#method.set_ttl"><code>IP_TTL</code></a>,
and <a href="struct.Socket.html#method.set_tos"><code>IP_TOS</code></a> are ignored.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ip_transparent" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1085-1090">source</a><h4 class="code-header">pub fn <a href="#method.ip_transparent" class="fnname">ip_transparent</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_TRANSPARENT</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_ip_transparent"><code>set_ip_transparent</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_ip_transparent" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1109-1118">source</a><h4 class="code-header">pub fn <a href="#method.set_ip_transparent" class="fnname">set_ip_transparent</a>(&amp;self, transparent: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_TRANSPARENT</code> option on this socket.</p>
<p>Setting this boolean option enables transparent proxying
on this socket. This socket option allows the calling
application to bind to a nonlocal IP address and operate
both as a client and a server with the foreign address as
the local endpoint. NOTE: this requires that routing be
set up in a way that packets going to the foreign address
are routed through the TProxy box (i.e., the system
hosting the application that employs the IP_TRANSPARENT
socket option). Enabling this socket option requires
superuser privileges (the <code>CAP_NET_ADMIN</code> capability).</p>
<p>TProxy redirection with the iptables TPROXY target also
requires that this option be set on the redirected socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_multicast_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1127-1133">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v4" class="fnname">join_multicast_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Join a multicast group using <code>IP_ADD_MEMBERSHIP</code> option on this socket.</p>
<p>This function specifies a new multicast group for this socket to join.
The address must be a valid multicast address, and <code>interface</code> is the
address of the local interface with which the system should join the
multicast group. If it’s [<code>Ipv4Addr::UNSPECIFIED</code>] (<code>INADDR_ANY</code>) then
an appropriate interface is chosen by the system.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_multicast_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1140-1153">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v4" class="fnname">leave_multicast_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Leave a multicast group using <code>IP_DROP_MEMBERSHIP</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.join_multicast_v4"><code>join_multicast_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_multicast_v4_n" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1170-1184">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v4_n" class="fnname">join_multicast_v4_n</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;<a class="enum" href="enum.InterfaceIndexOrAddress.html" title="enum socket2::InterfaceIndexOrAddress">InterfaceIndexOrAddress</a><br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Join a multicast group using <code>IP_ADD_MEMBERSHIP</code> option on this socket.</p>
<p>This function specifies a new multicast group for this socket to join.
The address must be a valid multicast address, and <code>interface</code> specifies
the local interface with which the system should join the multicast
group. See <a href="enum.InterfaceIndexOrAddress.html" title="InterfaceIndexOrAddress"><code>InterfaceIndexOrAddress</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_multicast_v4_n" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1200-1214">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v4_n" class="fnname">leave_multicast_v4_n</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;<a class="enum" href="enum.InterfaceIndexOrAddress.html" title="enum socket2::InterfaceIndexOrAddress">InterfaceIndexOrAddress</a><br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Leave a multicast group using <code>IP_DROP_MEMBERSHIP</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.join_multicast_v4_n"><code>join_multicast_v4_n</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_ssm_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1232-1251">source</a><h4 class="code-header">pub fn <a href="#method.join_ssm_v4" class="fnname">join_ssm_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;source: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;group: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Join a multicast SSM channel using <code>IP_ADD_SOURCE_MEMBERSHIP</code> option on this socket.</p>
<p>This function specifies a new multicast channel for this socket to join.
The group must be a valid SSM group address, the source must be the address of the sender
and <code>interface</code> is the address of the local interface with which the system should join the
multicast group. If it’s [<code>Ipv4Addr::UNSPECIFIED</code>] (<code>INADDR_ANY</code>) then
an appropriate interface is chosen by the system.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_ssm_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1267-1286">source</a><h4 class="code-header">pub fn <a href="#method.leave_ssm_v4" class="fnname">leave_ssm_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;source: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;group: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Leave a multicast group using <code>IP_DROP_SOURCE_MEMBERSHIP</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.join_ssm_v4"><code>join_ssm_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_if_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1293-1297">source</a><h4 class="code-header">pub fn <a href="#method.multicast_if_v4" class="fnname">multicast_if_v4</a>(&amp;self) -&gt; Result&lt;Ipv4Addr&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_MULTICAST_IF</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_if_v4"><code>set_multicast_if_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_if_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1302-1312">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_if_v4" class="fnname">set_multicast_if_v4</a>(&amp;self, interface: &amp;Ipv4Addr) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_MULTICAST_IF</code> option for this socket.</p>
<p>Specifies the interface to use for routing multicast packets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_loop_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1319-1324">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v4" class="fnname">multicast_loop_v4</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_MULTICAST_LOOP</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_loop_v4"><code>set_multicast_loop_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_loop_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1330-1339">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v4" class="fnname">set_multicast_loop_v4</a>(&amp;self, loop_v4: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_MULTICAST_LOOP</code> option for this socket.</p>
<p>If enabled, multicast packets will be looped back to the local socket.
Note that this may not have any affect on IPv6 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_ttl_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1346-1351">source</a><h4 class="code-header">pub fn <a href="#method.multicast_ttl_v4" class="fnname">multicast_ttl_v4</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_MULTICAST_TTL</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_ttl_v4"><code>set_multicast_ttl_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_ttl_v4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1360-1369">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_ttl_v4" class="fnname">set_multicast_ttl_v4</a>(&amp;self, ttl: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_MULTICAST_TTL</code> option for this socket.</p>
<p>Indicates the time-to-live value of outgoing multicast packets for
this socket. The default value is 1 which means that multicast packets
don’t leave the local network unless explicitly requested.</p>
<p>Note that this may not have any affect on IPv6 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ttl" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1376-1380">source</a><h4 class="code-header">pub fn <a href="#method.ttl" class="fnname">ttl</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_TTL</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_ttl"><code>set_ttl</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_ttl" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1386-1388">source</a><h4 class="code-header">pub fn <a href="#method.set_ttl" class="fnname">set_ttl</a>(&amp;self, ttl: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_TTL</code> option for this socket.</p>
<p>This value sets the time-to-live field that is used in every packet sent
from this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_tos" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1403-1405">source</a><h4 class="code-header">pub fn <a href="#method.set_tos" class="fnname">set_tos</a>(&amp;self, tos: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_TOS</code> option for this socket.</p>
<p>This value sets the type-of-service field that is used in every packet
sent from this socket.</p>
<p>NOTE: <a href="https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options">https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options</a>
documents that not all versions of windows support <code>IP_TOS</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.tos" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1421-1425">source</a><h4 class="code-header">pub fn <a href="#method.tos" class="fnname">tos</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_TOS</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_tos"><code>set_tos</code></a>.</p>
<p>NOTE: <a href="https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options">https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options</a>
documents that not all versions of windows support <code>IP_TOS</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_recv_tos" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1443-1454">source</a><h4 class="code-header">pub fn <a href="#method.set_recv_tos" class="fnname">set_recv_tos</a>(&amp;self, recv_tos: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IP_RECVTOS</code> option for this socket.</p>
<p>If enabled, the IP_TOS ancillary message is passed with
incoming packets. It contains a byte which specifies the
Type of Service/Precedence field of the packet header.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_tos" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1472-1477">source</a><h4 class="code-header">pub fn <a href="#method.recv_tos" class="fnname">recv_tos</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_RECVTOS</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_recv_tos"><code>set_recv_tos</code></a>.</p>
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_multicast_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1494-1508">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v6" class="fnname">join_multicast_v6</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv6Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: u32<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Join a multicast group using <code>IPV6_ADD_MEMBERSHIP</code> option on this socket.</p>
<p>Some OSs use <code>IPV6_JOIN_GROUP</code> for this option.</p>
<p>This function specifies a new multicast group for this socket to join.
The address must be a valid multicast address, and <code>interface</code> is the
index of the interface to join/leave (or 0 to indicate any interface).</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_multicast_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1518-1532">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v6" class="fnname">leave_multicast_v6</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv6Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: u32<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Leave a multicast group using <code>IPV6_DROP_MEMBERSHIP</code> option on this socket.</p>
<p>Some OSs use <code>IPV6_LEAVE_GROUP</code> for this option.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.join_multicast_v6"><code>join_multicast_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_hops_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1539-1544">source</a><h4 class="code-header">pub fn <a href="#method.multicast_hops_v6" class="fnname">multicast_hops_v6</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_MULTICAST_HOPS</code> option for this socket</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_hops_v6"><code>set_multicast_hops_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_hops_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1551-1560">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_hops_v6" class="fnname">set_multicast_hops_v6</a>(&amp;self, hops: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IPV6_MULTICAST_HOPS</code> option for this socket</p>
<p>Indicates the number of “routers” multicast packets will transit for
this socket. The default value is 1 which means that multicast packets
don’t leave the local network unless explicitly requested.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_if_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1567-1572">source</a><h4 class="code-header">pub fn <a href="#method.multicast_if_v6" class="fnname">multicast_if_v6</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_MULTICAST_IF</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_if_v6"><code>set_multicast_if_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_if_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1579-1588">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_if_v6" class="fnname">set_multicast_if_v6</a>(&amp;self, interface: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IPV6_MULTICAST_IF</code> option for this socket.</p>
<p>Specifies the interface to use for routing multicast packets. Unlike
ipv4, this is generally required in ipv6 contexts where network routing
prefixes may overlap.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_loop_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1595-1600">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v6" class="fnname">multicast_loop_v6</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_MULTICAST_LOOP</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_multicast_loop_v6"><code>set_multicast_loop_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_loop_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1606-1615">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v6" class="fnname">set_multicast_loop_v6</a>(&amp;self, loop_v6: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>IPV6_MULTICAST_LOOP</code> option for this socket.</p>
<p>Controls whether this socket sees the multicast packets it sends itself.
Note that this may not have any affect on IPv4 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.unicast_hops_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1620-1625">source</a><h4 class="code-header">pub fn <a href="#method.unicast_hops_v6" class="fnname">unicast_hops_v6</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_UNICAST_HOPS</code> option for this socket.</p>
<p>Specifies the hop limit for ipv6 unicast packets</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_unicast_hops_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1630-1639">source</a><h4 class="code-header">pub fn <a href="#method.set_unicast_hops_v6" class="fnname">set_unicast_hops_v6</a>(&amp;self, hops: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value for the <code>IPV6_UNICAST_HOPS</code> option on this socket.</p>
<p>Specifies the hop limit for ipv6 unicast packets</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.only_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1646-1651">source</a><h4 class="code-header">pub fn <a href="#method.only_v6" class="fnname">only_v6</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_V6ONLY</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_only_v6"><code>set_only_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_only_v6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1661-1670">source</a><h4 class="code-header">pub fn <a href="#method.set_only_v6" class="fnname">set_only_v6</a>(&amp;self, only_v6: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value for the <code>IPV6_V6ONLY</code> option on this socket.</p>
<p>If this is set to <code>true</code> then the socket is restricted to sending and
receiving IPv6 packets only. In this case two IPv4 and IPv6 applications
can bind the same port at the same time.</p>
<p>If this is set to <code>false</code> then the socket can be used to send and
receive packets from an IPv4-mapped IPv6 address.</p>
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.keepalive_time" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1697-1699">source</a><h4 class="code-header">pub fn <a href="#method.keepalive_time" class="fnname">keepalive_time</a>(&amp;self) -&gt; Result&lt;Duration&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_KEEPIDLE</code> option on this socket.</p>
<p>This returns the value of <code>TCP_KEEPALIVE</code> on macOS and iOS and <code>TCP_KEEPIDLE</code> on all other
supported Unix operating systems.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.keepalive_interval" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1736-1741">source</a><h4 class="code-header">pub fn <a href="#method.keepalive_interval" class="fnname">keepalive_interval</a>(&amp;self) -&gt; Result&lt;Duration&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_KEEPINTVL</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_tcp_keepalive"><code>set_tcp_keepalive</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.keepalive_retries" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1778-1783">source</a><h4 class="code-header">pub fn <a href="#method.keepalive_retries" class="fnname">keepalive_retries</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_KEEPCNT</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_tcp_keepalive"><code>set_tcp_keepalive</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_tcp_keepalive" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1823-1826">source</a><h4 class="code-header">pub fn <a href="#method.set_tcp_keepalive" class="fnname">set_tcp_keepalive</a>(&amp;self, params: &amp;<a class="struct" href="struct.TcpKeepalive.html" title="struct socket2::TcpKeepalive">TcpKeepalive</a>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set parameters configuring TCP keepalive probes for this socket.</p>
<p>The supported parameters depend on the operating system, and are
configured using the <a href="struct.TcpKeepalive.html" title="TcpKeepalive"><code>TcpKeepalive</code></a> struct. At a minimum, all systems
support configuring the <a href="struct.TcpKeepalive.html#method.with_time">keepalive time</a>: the time after which the OS
will start sending keepalive messages on an idle connection.</p>
<h5 id="notes-6"><a href="#notes-6">Notes</a></h5>
<ul>
<li>This will enable <code>SO_KEEPALIVE</code> on this socket, if it is not already
enabled.</li>
<li>On some platforms, such as Windows, any keepalive parameters <em>not</em>
configured by the <code>TcpKeepalive</code> struct passed to this function may be
overwritten with their default values. Therefore, this function should
either only be called once per socket, or the same parameters should
be passed every time it is called.</li>
</ul>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>socket2::{Socket, TcpKeepalive, Domain, Type};
<span class="kw">let </span>socket = Socket::new(Domain::IPV4, Type::STREAM, <span class="prelude-val">None</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>keepalive = TcpKeepalive::new()
.with_time(Duration::from_secs(<span class="number">4</span>));
<span class="comment">// Depending on the target operating system, we may also be able to
// configure the keepalive probe interval and/or the number of
// retries here as well.
</span>socket.set_tcp_keepalive(<span class="kw-2">&amp;</span>keepalive)<span class="question-mark">?</span>;</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.nodelay" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1833-1838">source</a><h4 class="code-header">pub fn <a href="#method.nodelay" class="fnname">nodelay</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_NODELAY</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_nodelay"><code>set_nodelay</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_nodelay" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/socket.rs.html#1847-1856">source</a><h4 class="code-header">pub fn <a href="#method.set_nodelay" class="fnname">set_nodelay</a>(&amp;self, nodelay: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>TCP_NODELAY</code> option on this socket.</p>
<p>If set, this option disables the Nagle algorithm. This means that
segments are always sent as soon as possible, even if there is only a
small amount of data. When not set, data is buffered until there is a
sufficient amount to send out, thereby avoiding the frequent sending of
small packets.</p>
</div></details></div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.accept4" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1116-1118">source</a><h4 class="code-header">pub fn <a href="#method.accept4" class="fnname">accept4</a>(&amp;self, flags: <a class="type" href="../libc/unix/type.c_int.html" title="type libc::unix::c_int">c_int</a>) -&gt; Result&lt;(<a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a>, <a class="struct" href="struct.SockAddr.html" title="struct socket2::SockAddr">SockAddr</a>)&gt;</h4></section></summary><div class="docblock"><p>Accept a new incoming connection from this listener.</p>
<p>This function directly corresponds to the <code>accept4(2)</code> function.</p>
<p>This function will block the calling thread until a new connection is
established. When established, the corresponding <code>Socket</code> and the remote
peer’s address will be returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_cloexec" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1147-1149">source</a><h4 class="code-header">pub fn <a href="#method.set_cloexec" class="fnname">set_cloexec</a>(&amp;self, close_on_exec: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets <code>CLOEXEC</code> on the socket.</p>
<h5 id="notes-7"><a href="#notes-7">Notes</a></h5>
<p>On supported platforms you can use <a href="struct.Type.html#method.cloexec" title="Type::cloexec"><code>Type::cloexec</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_nosigpipe" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1172-1174">source</a><h4 class="code-header">pub fn <a href="#method.set_nosigpipe" class="fnname">set_nosigpipe</a>(&amp;self, nosigpipe: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets <code>SO_NOSIGPIPE</code> on the socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.mss" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1195-1200">source</a><h4 class="code-header">pub fn <a href="#method.mss" class="fnname">mss</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>TCP_MAXSEG</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_mss"><code>set_mss</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_mss" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1208-1217">source</a><h4 class="code-header">pub fn <a href="#method.set_mss" class="fnname">set_mss</a>(&amp;self, mss: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value of the <code>TCP_MAXSEG</code> option on this socket.</p>
<p>The <code>TCP_MAXSEG</code> option denotes the TCP Maximum Segment Size and is only
available on TCP sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_listener" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1242-1247">source</a><h4 class="code-header">pub fn <a href="#method.is_listener" class="fnname">is_listener</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>listen(2)</code> was called on this socket by checking the
<code>SO_ACCEPTCONN</code> option on this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.domain" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1271-1273">source</a><h4 class="code-header">pub fn <a href="#method.domain" class="fnname">domain</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="struct.Domain.html" title="struct socket2::Domain">Domain</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the <a href="struct.Domain.html" title="Domain"><code>Domain</code></a> of this socket by checking the <code>SO_DOMAIN</code> option
on this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.protocol" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1298-1306">source</a><h4 class="code-header">pub fn <a href="#method.protocol" class="fnname">protocol</a>(&amp;self) -&gt; Result&lt;Option&lt;<a class="struct" href="struct.Protocol.html" title="struct socket2::Protocol">Protocol</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns the <a href="struct.Protocol.html" title="Protocol"><code>Protocol</code></a> of this socket by checking the <code>SO_PROTOCOL</code>
option on this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.mark" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1325-1330">source</a><h4 class="code-header">pub fn <a href="#method.mark" class="fnname">mark</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Gets the value for the <code>SO_MARK</code> option on this socket.</p>
<p>This value gets the socket mark field for each packet sent through
this socket.</p>
<p>On Linux this function requires the <code>CAP_NET_ADMIN</code> capability.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_mark" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1350-1359">source</a><h4 class="code-header">pub fn <a href="#method.set_mark" class="fnname">set_mark</a>(&amp;self, mark: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value for the <code>SO_MARK</code> option on this socket.</p>
<p>This value sets the socket mark field for each packet sent through
this socket. Changing the mark can be used for mark-based routing
without netfilter or for packet filtering.</p>
<p>On Linux this function requires the <code>CAP_NET_ADMIN</code> capability.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cork" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1377-1382">source</a><h4 class="code-header">pub fn <a href="#method.cork" class="fnname">cork</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_CORK</code> option on this socket.</p>
<p>For more information about this option, see <a href="Socket::set_cork"><code>set_cork</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_cork" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1401-1410">source</a><h4 class="code-header">pub fn <a href="#method.set_cork" class="fnname">set_cork</a>(&amp;self, cork: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>TCP_CORK</code> option on this socket.</p>
<p>If set, don’t send out partial frames. All queued partial frames are
sent when the option is cleared again. There is a 200 millisecond ceiling on
the time for which output is corked by <code>TCP_CORK</code>. If this ceiling is reached,
then queued data is automatically transmitted.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.quickack" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1428-1433">source</a><h4 class="code-header">pub fn <a href="#method.quickack" class="fnname">quickack</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_QUICKACK</code> option on this socket.</p>
<p>For more information about this option, see <a href="Socket::set_quickack"><code>set_quickack</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_quickack" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1452-1461">source</a><h4 class="code-header">pub fn <a href="#method.set_quickack" class="fnname">set_quickack</a>(&amp;self, quickack: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>TCP_QUICKACK</code> option on this socket.</p>
<p>If set, acks are sent immediately, rather than delayed if needed in accordance to normal
TCP operation. This flag is not permanent, it only enables a switch to or from quickack mode.
Subsequent operation of the TCP protocol will once again enter/leave quickack mode depending on
internal protocol processing and factors such as delayed ack timeouts occurring and data transfer.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.thin_linear_timeouts" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1479-1488">source</a><h4 class="code-header">pub fn <a href="#method.thin_linear_timeouts" class="fnname">thin_linear_timeouts</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_THIN_LINEAR_TIMEOUTS</code> option on this socket.</p>
<p>For more information about this option, see <a href="Socket::set_thin_linear_timeouts"><code>set_thin_linear_timeouts</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_thin_linear_timeouts" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1506-1515">source</a><h4 class="code-header">pub fn <a href="#method.set_thin_linear_timeouts" class="fnname">set_thin_linear_timeouts</a>(&amp;self, timeouts: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>TCP_THIN_LINEAR_TIMEOUTS</code> option on this socket.</p>
<p>If set, the kernel will dynamically detect a thin-stream connection if there are less than four packets in flight.
With less than four packets in flight the normal TCP fast retransmission will not be effective.
The kernel will modify the retransmission to avoid the very high latencies that thin stream suffer because of exponential backoff.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.device" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1531-1550">source</a><h4 class="code-header">pub fn <a href="#method.device" class="fnname">device</a>(&amp;self) -&gt; Result&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Gets the value for the <code>SO_BINDTODEVICE</code> option on this socket.</p>
<p>This value gets the socket binded device’s interface name.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.bind_device" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1570-1584">source</a><h4 class="code-header">pub fn <a href="#method.bind_device" class="fnname">bind_device</a>(&amp;self, interface: Option&lt;&amp;[u8]&gt;) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value for the <code>SO_BINDTODEVICE</code> option on this socket.</p>
<p>If a socket is bound to an interface, only packets received from that
particular interface are processed by the socket. Note that this only
works for some socket types, particularly <code>AF_INET</code> sockets.</p>
<p>If <code>interface</code> is <code>None</code> or an empty string it removes the binding.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cpu_affinity" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1639-1644">source</a><h4 class="code-header">pub fn <a href="#method.cpu_affinity" class="fnname">cpu_affinity</a>(&amp;self) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_INCOMING_CPU</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_cpu_affinity"><code>set_cpu_affinity</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_cpu_affinity" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1651-1660">source</a><h4 class="code-header">pub fn <a href="#method.set_cpu_affinity" class="fnname">set_cpu_affinity</a>(&amp;self, cpu: usize) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_INCOMING_CPU</code> option on this socket.</p>
<p>Sets the CPU affinity of the socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.reuse_port" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1679-1684">source</a><h4 class="code-header">pub fn <a href="#method.reuse_port" class="fnname">reuse_port</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_REUSEPORT</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_reuse_port"><code>set_reuse_port</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_reuse_port" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1703-1712">source</a><h4 class="code-header">pub fn <a href="#method.set_reuse_port" class="fnname">set_reuse_port</a>(&amp;self, reuse: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>SO_REUSEPORT</code> option on this socket.</p>
<p>This indicates that further calls to <code>bind</code> may allow reuse of local
addresses. For IPv4 sockets this means that a socket may bind even when
there’s a socket already listening on this port.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.freebind" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1730-1735">source</a><h4 class="code-header">pub fn <a href="#method.freebind" class="fnname">freebind</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IP_FREEBIND</code> option on this socket.</p>
<p>For more information about this option, see <a href="struct.Socket.html#method.set_freebind"><code>set_freebind</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_freebind" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1755-1764">source</a><h4 class="code-header">pub fn <a href="#method.set_freebind" class="fnname">set_freebind</a>(&amp;self, freebind: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>IP_FREEBIND</code> option on this socket.</p>
<p>If enabled, this boolean option allows binding to an IP address that is
nonlocal or does not (yet) exist. This permits listening on a socket,
without requiring the underlying network interface or the specified
dynamic IP address to be up at the time that the application is trying
to bind to it.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.freebind_ipv6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1778-1783">source</a><h4 class="code-header">pub fn <a href="#method.freebind_ipv6" class="fnname">freebind_ipv6</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_FREEBIND</code> option on this socket.</p>
<p>This is an IPv6 counterpart of <code>IP_FREEBIND</code> socket option on
Android/Linux. For more information about this option, see
<a href="struct.Socket.html#method.set_freebind"><code>set_freebind</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_freebind_ipv6" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1820-1829">source</a><h4 class="code-header">pub fn <a href="#method.set_freebind_ipv6" class="fnname">set_freebind_ipv6</a>(&amp;self, freebind: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set value for the <code>IPV6_FREEBIND</code> option on this socket.</p>
<p>This is an IPv6 counterpart of <code>IP_FREEBIND</code> socket option on
Android/Linux. For more information about this option, see
<a href="struct.Socket.html#method.set_freebind"><code>set_freebind</code></a>.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<p>On Linux:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>socket2::{Domain, Socket, Type};
<span class="kw">use </span>std::io::{<span class="self">self</span>, Error, ErrorKind};
<span class="kw">fn </span>enable_freebind(socket: <span class="kw-2">&amp;</span>Socket) -&gt; io::Result&lt;()&gt; {
<span class="kw">match </span>socket.domain()<span class="question-mark">? </span>{
Domain::IPV4 =&gt; socket.set_freebind(<span class="bool-val">true</span>)<span class="question-mark">?</span>,
Domain::IPV6 =&gt; socket.set_freebind_ipv6(<span class="bool-val">true</span>)<span class="question-mark">?</span>,
<span class="kw">_ </span>=&gt; <span class="kw">return </span><span class="prelude-val">Err</span>(Error::new(ErrorKind::Other, <span class="string">&quot;unsupported domain&quot;</span>)),
};
<span class="prelude-val">Ok</span>(())
}
</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sendfile" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1870-1880">source</a><h4 class="code-header">pub fn <a href="#method.sendfile" class="fnname">sendfile</a>&lt;F&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;file: &amp;F,<br>&nbsp;&nbsp;&nbsp;&nbsp;offset: usize,<br>&nbsp;&nbsp;&nbsp;&nbsp;length: Option&lt;NonZeroUsize&gt;<br>) -&gt; Result&lt;usize&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: AsRawFd,</span></h4></section></summary><div class="docblock"><p>Copies data between a <code>file</code> and this socket using the <code>sendfile(2)</code>
system call. Because this copying is done within the kernel,
<code>sendfile()</code> is more efficient than the combination of <code>read(2)</code> and
<code>write(2)</code>, which would require transferring data to and from user
space.</p>
<p>Different OSs support different kinds of <code>file</code>s, see the OS
documentation for what kind of files are supported. Generally <em>regular</em>
files are supported by all OSs.</p>
<p>The <code>offset</code> is the absolute offset into the <code>file</code> to use as starting
point.</p>
<p>Depending on the OS this function <em>may</em> change the offset of <code>file</code>. For
the best results reset the offset of the file before using it again.</p>
<p>The <code>length</code> determines how many bytes to send, where a length of <code>None</code>
means it will try to send all bytes.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_tcp_user_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1969-1981">source</a><h4 class="code-header">pub fn <a href="#method.set_tcp_user_timeout" class="fnname">set_tcp_user_timeout</a>(&amp;self, timeout: Option&lt;Duration&gt;) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Set the value of the <code>TCP_USER_TIMEOUT</code> option on this socket.</p>
<p>If set, this specifies the maximum amount of time that transmitted data may remain
unacknowledged or buffered data may remain untransmitted before TCP will forcibly close the
corresponding connection.</p>
<p>Setting <code>timeout</code> to <code>None</code> or a zero duration causes the system default timeouts to
be used. If <code>timeout</code> in milliseconds is larger than <code>c_uint::MAX</code>, the timeout is clamped
to <code>c_uint::MAX</code>. For example, when <code>c_uint</code> is a 32-bit value, this limits the timeout to
approximately 49.71 days.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.tcp_user_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#1999-2010">source</a><h4 class="code-header">pub fn <a href="#method.tcp_user_timeout" class="fnname">tcp_user_timeout</a>(&amp;self) -&gt; Result&lt;Option&lt;Duration&gt;&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>TCP_USER_TIMEOUT</code> option on this socket.</p>
<p>For more information about this option, see <a href="Socket::set_tcp_user_timeout"><code>set_tcp_user_timeout</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.attach_filter" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#2019-2033">source</a><h4 class="code-header">pub fn <a href="#method.attach_filter" class="fnname">attach_filter</a>(&amp;self, filters: &amp;[<a class="struct" href="../libc/unix/linux_like/linux/struct.sock_filter.html" title="struct libc::unix::linux_like::linux::sock_filter">sock_filter</a>]) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Attach Berkeley Packet Filter(BPF) on this socket.</p>
<p>BPF allows a user-space program to attach a filter onto any socket
and allow or disallow certain types of data to come through the socket.</p>
<p>For more information about this option, see <a href="https://www.kernel.org/doc/html/v5.12/networking/filter.html">filter</a></p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.detach_filter" class="method has-srclink"><a class="srclink rightside" href="../src/socket2/sys/unix.rs.html#2039-2041">source</a><h4 class="code-header">pub fn <a href="#method.detach_filter" class="fnname">detach_filter</a>(&amp;self) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Detach Berkeley Packet Filter(BPF) from this socket.</p>
<p>For more information about this option, see [<code>attach_filter</code>]</p>
</div></details></div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-SockRef%3C%27_%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#139-147">source</a><a href="#impl-Debug-for-SockRef%3C%27_%3E" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'_&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#140-146">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Deref-for-SockRef%3C%27s%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#95-101">source</a><a href="#impl-Deref-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; Deref for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Target" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Target" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Target</a> = <a class="struct" href="struct.Socket.html" title="struct socket2::Socket">Socket</a></h4></section></summary><div class='docblock'>The resulting type after dereferencing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#98-100">source</a><a href="#method.deref" class="anchor"></a><h4 class="code-header">fn <a class="fnname">deref</a>(&amp;self) -&gt; &amp;Self::Target</h4></section></summary><div class='docblock'>Dereferences the value.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3C%26%27s%20S%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#106-119">source</a><a href="#impl-From%3C%26%27s%20S%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s, S&gt; From&lt;&amp;'s S&gt; for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: AsRawFd,</span></h3></section></summary><div class="docblock"><p>On Windows, a corresponding <code>From&lt;&amp;impl AsRawSocket&gt;</code> implementation exists.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/socket2/sockref.rs.html#111-118">source</a><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(socket: &amp;'s S) -&gt; Self</h4></section></summary><div class="docblock"><p>The caller must ensure <code>S</code> is actually a socket.</p>
</div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; RefUnwindSafe for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section><section id="impl-Send-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Send-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; Send for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section><section id="impl-Sync-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Sync-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; Sync for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section><section id="impl-Unpin-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Unpin-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; Unpin for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section><section id="impl-UnwindSafe-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-UnwindSafe-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;'s&gt; UnwindSafe for <a class="struct" href="struct.SockRef.html" title="struct socket2::SockRef">SockRef</a>&lt;'s&gt;</h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Any-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-SockRef%3C%27s%3E" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-SockRef%3C%27s%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></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>