blob: 37997ed0450bad4e9e265f5c51c575c10b55f89b [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 TCP socket that has not yet been converted to a `TcpStream` or `TcpListener`."><meta name="keywords" content="rust, rustlang, rust-lang, TcpSocket"><title>TcpSocket in tokio::net - 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="../../tokio/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="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">TcpSocket</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.bind">bind</a></li><li><a href="#method.bind_device">bind_device</a></li><li><a href="#method.connect">connect</a></li><li><a href="#method.device">device</a></li><li><a href="#method.from_std_stream">from_std_stream</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.new_v4">new_v4</a></li><li><a href="#method.new_v6">new_v6</a></li><li><a href="#method.recv_buffer_size">recv_buffer_size</a></li><li><a href="#method.reuseaddr">reuseaddr</a></li><li><a href="#method.reuseport">reuseport</a></li><li><a href="#method.send_buffer_size">send_buffer_size</a></li><li><a href="#method.set_linger">set_linger</a></li><li><a href="#method.set_recv_buffer_size">set_recv_buffer_size</a></li><li><a href="#method.set_reuseaddr">set_reuseaddr</a></li><li><a href="#method.set_reuseport">set_reuseport</a></li><li><a href="#method.set_send_buffer_size">set_send_buffer_size</a></li><li><a href="#method.set_tos">set_tos</a></li><li><a href="#method.take_error">take_error</a></li><li><a href="#method.tos">tos</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsFd-for-TcpSocket">AsFd</a></li><li><a href="#impl-AsRawFd-for-TcpSocket">AsRawFd</a></li><li><a href="#impl-Debug-for-TcpSocket">Debug</a></li><li><a href="#impl-FromRawFd-for-TcpSocket">FromRawFd</a></li><li><a href="#impl-IntoRawFd-for-TcpSocket">IntoRawFd</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-TcpSocket">RefUnwindSafe</a></li><li><a href="#impl-Send-for-TcpSocket">Send</a></li><li><a href="#impl-Sync-for-TcpSocket">Sync</a></li><li><a href="#impl-Unpin-for-TcpSocket">Unpin</a></li><li><a href="#impl-UnwindSafe-for-TcpSocket">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-TcpSocket">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-TcpSocket">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-TcpSocket">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-TcpSocket">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-TcpSocket">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-TcpSocket">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-TcpSocket">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In tokio::net</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">tokio</a>::<wbr><a href="index.html">net</a>::<wbr><a class="struct" href="#">TcpSocket</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/tokio/net/tcp/socket.rs.html#92-94">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 TcpSocket { /* 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 TCP socket that has not yet been converted to a <code>TcpStream</code> or
<code>TcpListener</code>.</p>
<p><code>TcpSocket</code> wraps an operating system socket and enables the caller to
configure the socket before establishing a TCP connection or accepting
inbound connections. The caller is able to set socket option and explicitly
bind the socket with a socket address.</p>
<p>The underlying socket is closed when the <code>TcpSocket</code> value is dropped.</p>
<p><code>TcpSocket</code> should only be used directly if the default configuration used
by <code>TcpStream::connect</code> and <code>TcpListener::bind</code> does not meet the required
use case.</p>
<p>Calling <code>TcpStream::connect(&quot;127.0.0.1:8080&quot;)</code> is equivalent to:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
<span class="kw">let </span>stream = socket.connect(addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
<p>Calling <code>TcpListener::bind(&quot;127.0.0.1:8080&quot;)</code> is equivalent to:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
<span class="comment">// On platforms with Berkeley-derived sockets, this allows to quickly
// rebind a socket, without needing to wait for the OS to clean up the
// previous one.
//
// On Windows, this allows rebinding sockets which are actively in use,
// which allows “socket hijacking”, so we explicitly don&#39;t set it here.
// https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
</span>socket.set_reuseaddr(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
<p>Setting socket options not explicitly provided by <code>TcpSocket</code> may be done by
accessing the <code>RawFd</code>/<code>RawSocket</code> using <a href="https://doc.rust-lang.org/std/os/unix/io/trait.AsRawFd.html"><code>AsRawFd</code></a>/<a href="https://doc.rust-lang.org/std/os/windows/io/trait.AsRawSocket.html"><code>AsRawSocket</code></a> and
setting the option with a crate like <a href="https://docs.rs/socket2/"><code>socket2</code></a>.</p>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#97-721">source</a><a href="#impl-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#127-129">source</a><h4 class="code-header">pub fn <a href="#method.new_v4" class="fnname">new_v4</a>() -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a new socket configured for IPv4.</p>
<p>Calls <code>socket(2)</code> with <code>AF_INET</code> and <code>SOCK_STREAM</code>.</p>
<h5 id="returns"><a href="#returns">Returns</a></h5>
<p>On success, the newly created <code>TcpSocket</code> is returned. If an error is
encountered, it is returned instead.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<p>Create a new IPv4 socket and start listening.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">128</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#160-162">source</a><h4 class="code-header">pub fn <a href="#method.new_v6" class="fnname">new_v6</a>() -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a new socket configured for IPv6.</p>
<p>Calls <code>socket(2)</code> with <code>AF_INET6</code> and <code>SOCK_STREAM</code>.</p>
<h5 id="returns-1"><a href="#returns-1">Returns</a></h5>
<p>On success, the newly created <code>TcpSocket</code> is returned. If an error is
encountered, it is returned instead.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<p>Create a new IPv6 socket and start listening.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;[::1]:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v6()<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">128</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_reuseaddr" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#218-220">source</a><h4 class="code-header">pub fn <a href="#method.set_reuseaddr" class="fnname">set_reuseaddr</a>(&amp;self, reuseaddr: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Allows the socket to bind to an in-use address.</p>
<p>Behavior is platform specific. Refer to the target platform’s
documentation for more details.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.set_reuseaddr(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.reuseaddr" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#244-246">source</a><h4 class="code-header">pub fn <a href="#method.reuseaddr" class="fnname">reuseaddr</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>&gt;</h4></section></summary><div class="docblock"><p>Retrieves the value set for <code>SO_REUSEADDR</code> on this socket.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.set_reuseaddr(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(socket.reuseaddr().unwrap());
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_reuseport" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#278-280">source</a><h4 class="code-header">pub fn <a href="#method.set_reuseport" class="fnname">set_reuseport</a>(&amp;self, reuseport: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Allows the socket to bind to an in-use port. Only available for unix systems
(excluding Solaris &amp; Illumos).</p>
<p>Behavior is platform specific. Refer to the target platform’s
documentation for more details.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.set_reuseport(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.reuseport" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#313-315">source</a><h4 class="code-header">pub fn <a href="#method.reuseport" class="fnname">reuseport</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>&gt;</h4></section></summary><div class="docblock"><p>Allows the socket to bind to an in-use port. Only available for unix systems
(excluding Solaris &amp; Illumos).</p>
<p>Behavior is platform specific. Refer to the target platform’s
documentation for more details.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.set_reuseport(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(socket.reuseport().unwrap());
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</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/tokio/net/tcp/socket.rs.html#320-322">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: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Sets the size of the TCP send buffer on this socket.</p>
<p>On most operating systems, this sets the <code>SO_SNDBUF</code> socket option.</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/tokio/net/tcp/socket.rs.html#347-349">source</a><h4 class="code-header">pub fn <a href="#method.send_buffer_size" class="fnname">send_buffer_size</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the size of the TCP send buffer for this socket.</p>
<p>On most operating systems, this is the value of the <code>SO_SNDBUF</code> socket
option.</p>
<p>Note that if <a href="#method.set_send_buffer_size"><code>set_send_buffer_size</code></a> has been called on this socket
previously, the value returned by this function may not be the same as
the argument provided to <code>set_send_buffer_size</code>. This is for the
following reasons:</p>
<ul>
<li>Most operating systems have minimum and maximum allowed sizes for the
send buffer, and will clamp the provided value if it is below the
minimum or above the maximum. The minimum and maximum buffer sizes are
OS-dependent.</li>
<li>Linux will double the buffer size to account for internal bookkeeping
data, and returns the doubled value from <code>getsockopt(2)</code>. As per <code>man 7 socket</code>:
<blockquote>
<p>Sets or gets the maximum socket send buffer in bytes. The
kernel doubles this value (to allow space for bookkeeping
overhead) when it is set using <code>setsockopt(2)</code>, and this doubled
value is returned by <code>getsockopt(2)</code>.</p>
</blockquote>
</li>
</ul>
</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/tokio/net/tcp/socket.rs.html#354-356">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: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Sets the size of the TCP receive buffer on this socket.</p>
<p>On most operating systems, this sets the <code>SO_RCVBUF</code> socket option.</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/tokio/net/tcp/socket.rs.html#381-383">source</a><h4 class="code-header">pub fn <a href="#method.recv_buffer_size" class="fnname">recv_buffer_size</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the size of the TCP receive buffer for this socket.</p>
<p>On most operating systems, this is the value of the <code>SO_RCVBUF</code> socket
option.</p>
<p>Note that if <a href="#method.set_recv_buffer_size"><code>set_recv_buffer_size</code></a> has been called on this socket
previously, the value returned by this function may not be the same as
the argument provided to <code>set_send_buffer_size</code>. This is for the
following reasons:</p>
<ul>
<li>Most operating systems have minimum and maximum allowed sizes for the
receive buffer, and will clamp the provided value if it is below the
minimum or above the maximum. The minimum and maximum buffer sizes are
OS-dependent.</li>
<li>Linux will double the buffer size to account for internal bookkeeping
data, and returns the doubled value from <code>getsockopt(2)</code>. As per <code>man 7 socket</code>:
<blockquote>
<p>Sets or gets the maximum socket send buffer in bytes. The
kernel doubles this value (to allow space for bookkeeping
overhead) when it is set using <code>setsockopt(2)</code>, and this doubled
value is returned by <code>getsockopt(2)</code>.</p>
</blockquote>
</li>
</ul>
</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/tokio/net/tcp/socket.rs.html#393-395">source</a><h4 class="code-header">pub fn <a href="#method.set_linger" class="fnname">set_linger</a>(&amp;self, dur: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Sets the linger duration of this socket by setting the SO_LINGER option.</p>
<p>This option controls the action taken when a stream has unsent messages and the stream is
closed. If SO_LINGER is set, the system shall block the process until it can transmit the
data or until the time expires.</p>
<p>If SO_LINGER is not specified, and the socket is closed, the system handles the call in a
way that allows the process to continue as quickly as possible.</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/tokio/net/tcp/socket.rs.html#403-405">source</a><h4 class="code-header">pub fn <a href="#method.linger" class="fnname">linger</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Reads the linger duration for this socket by getting the <code>SO_LINGER</code>
option.</p>
<p>For more information about this option, see <a href="struct.TcpSocket.html#method.set_linger"><code>set_linger</code></a>.</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/tokio/net/tcp/socket.rs.html#431-433">source</a><h4 class="code-header">pub fn <a href="#method.tos" class="fnname">tos</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IP_TOS</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.TcpSocket.html#method.set_tos"><code>set_tos</code></a>.</p>
<p><strong>NOTE:</strong> On Windows, <code>IP_TOS</code> is only supported on <a href="https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options">Windows 8+ or
Windows Server 2012+.</a></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/tokio/net/tcp/socket.rs.html#458-460">source</a><h4 class="code-header">pub fn <a href="#method.set_tos" class="fnname">set_tos</a>(&amp;self, tos: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Sets the value for the <code>IP_TOS</code> option on this socket.</p>
<p>This value sets the type-of-service field that is used in every packet
sent from this socket.</p>
<p><strong>NOTE:</strong> On Windows, <code>IP_TOS</code> is only supported on <a href="https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options">Windows 8+ or
Windows Server 2012+.</a></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/tokio/net/tcp/socket.rs.html#470-472">source</a><h4 class="code-header">pub fn <a href="#method.device" class="fnname">device</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&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/tokio/net/tcp/socket.rs.html#486-488">source</a><h4 class="code-header">pub fn <a href="#method.bind_device" class="fnname">bind_device</a>(&amp;self, interface: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&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.local_addr" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#512-514">source</a><h4 class="code-header">pub fn <a href="#method.local_addr" class="fnname">local_addr</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/std/net/socket_addr/enum.SocketAddr.html" title="enum std::net::socket_addr::SocketAddr">SocketAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Gets the local address of this socket.</p>
<p>Will fail on windows if called before <code>bind</code>.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(socket.local_addr().unwrap().to_string(), <span class="string">&quot;127.0.0.1:8080&quot;</span>);
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</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/tokio/net/tcp/socket.rs.html#517-519">source</a><h4 class="code-header">pub fn <a href="#method.take_error" class="fnname">take_error</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns the value of the <code>SO_ERROR</code> option.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.bind" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#549-551">source</a><h4 class="code-header">pub fn <a href="#method.bind" class="fnname">bind</a>(&amp;self, addr: <a class="enum" href="https://doc.rust-lang.org/nightly/std/net/socket_addr/enum.SocketAddr.html" title="enum std::net::socket_addr::SocketAddr">SocketAddr</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Binds the socket to the given address.</p>
<p>This calls the <code>bind(2)</code> operating-system function. Behavior is
platform specific. Refer to the target platform’s documentation for more
details.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<p>Bind a socket before listening.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#585-613">source</a><h4 class="code-header">pub async fn <a href="#method.connect" class="fnname">connect</a>(self, addr: <a class="enum" href="https://doc.rust-lang.org/nightly/std/net/socket_addr/enum.SocketAddr.html" title="enum std::net::socket_addr::SocketAddr">SocketAddr</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.TcpStream.html" title="struct tokio::net::TcpStream">TcpStream</a>&gt;</h4></section></summary><div class="docblock"><p>Establishes a TCP connection with a peer at the specified socket address.</p>
<p>The <code>TcpSocket</code> is consumed. Once the connection is established, a
connected <a href="struct.TcpStream.html"><code>TcpStream</code></a> is returned. If the connection fails, the
encountered error is returned.</p>
<p>This calls the <code>connect(2)</code> operating-system function. Behavior is
platform specific. Refer to the target platform’s documentation for more
details.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<p>Connecting to a peer.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
<span class="kw">let </span>stream = socket.connect(addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.listen" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#650-669">source</a><h4 class="code-header">pub fn <a href="#method.listen" class="fnname">listen</a>(self, backlog: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.TcpListener.html" title="struct tokio::net::TcpListener">TcpListener</a>&gt;</h4></section></summary><div class="docblock"><p>Converts the socket into a <code>TcpListener</code>.</p>
<p><code>backlog</code> defines the maximum number of pending connections are queued
by the operating system at any given time. Connection are removed from
the queue with <a href="struct.TcpListener.html#method.accept"><code>TcpListener::accept</code></a>. When the queue is full, the
operating-system will start rejecting connections.</p>
<p>This calls the <code>listen(2)</code> operating-system function, marking the socket
as a passive socket. Behavior is platform specific. Refer to the target
platform’s documentation for more details.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<p>Create a <code>TcpListener</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>socket = TcpSocket::new_v4()<span class="question-mark">?</span>;
socket.bind(addr)<span class="question-mark">?</span>;
<span class="kw">let </span>listener = socket.listen(<span class="number">1024</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_std_stream" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#704-720">source</a><h4 class="code-header">pub fn <a href="#method.from_std_stream" class="fnname">from_std_stream</a>(std_stream: <a class="struct" href="https://doc.rust-lang.org/nightly/std/net/tcp/struct.TcpStream.html" title="struct std::net::tcp::TcpStream">TcpStream</a>) -&gt; <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h4></section></summary><div class="docblock"><p>Converts a <a href="https://doc.rust-lang.org/nightly/std/net/tcp/struct.TcpStream.html"><code>std::net::TcpStream</code></a> into a <code>TcpSocket</code>. The provided
socket must not have been connected prior to calling this function. This
function is typically used together with crates such as <a href="https://docs.rs/socket2/"><code>socket2</code></a> to
configure socket options that are not available on <code>TcpSocket</code>.</p>
<h5 id="notes"><a href="#notes">Notes</a></h5>
<p>The caller is responsible for ensuring that the socket is in
non-blocking mode. Otherwise all I/O operations on the socket
will block the thread, which will cause unexpected behavior.
Non-blocking mode can be set using <a href="https://doc.rust-lang.org/nightly/std/net/tcp/struct.TcpStream.html#method.set_nonblocking"><code>set_nonblocking</code></a>.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::TcpSocket;
<span class="kw">use </span>socket2::{Domain, Socket, Type};
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; std::io::Result&lt;()&gt; {
<span class="kw">let </span>socket2_socket = Socket::new(Domain::IPV4, Type::STREAM, <span class="prelude-val">None</span>)<span class="question-mark">?</span>;
socket2_socket.set_nonblocking(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>socket = TcpSocket::from_std_stream(socket2_socket.into());
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details></div></details></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-AsFd-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#747-751">source</a><a href="#impl-AsFd-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html" title="trait std::os::fd::owned::AsFd">AsFd</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#748-750">source</a><a href="#method.as_fd" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd" class="fnname">as_fd</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/std/os/fd/owned/struct.BorrowedFd.html" title="struct std::os::fd::owned::BorrowedFd">BorrowedFd</a>&lt;'_&gt;</h4></section></summary><div class='docblock'>Borrows the file descriptor. <a href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRawFd-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#740-744">source</a><a href="#impl-AsRawFd-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#741-743">source</a><a href="#method.as_raw_fd" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd" class="fnname">as_raw_fd</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a></h4></section></summary><div class='docblock'>Extracts the raw file descriptor. <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#733-737">source</a><a href="#impl-Debug-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></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/tokio/net/tcp/socket.rs.html#734-736">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, fmt: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-FromRawFd-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#754-765">source</a><a href="#impl-FromRawFd-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.FromRawFd.html" title="trait std::os::fd::raw::FromRawFd">FromRawFd</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#761-764">source</a><a href="#method.from_raw_fd" class="anchor"></a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.FromRawFd.html#tymethod.from_raw_fd" class="fnname">from_raw_fd</a>(fd: <a class="type" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a>) -&gt; <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h4></section></summary><div class="docblock"><p>Converts a <code>RawFd</code> to a <code>TcpSocket</code>.</p>
<h5 id="notes-1"><a href="#notes-1">Notes</a></h5>
<p>The caller is responsible for ensuring that the socket is in
non-blocking mode.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-IntoRawFd-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#768-772">source</a><a href="#impl-IntoRawFd-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.IntoRawFd.html" title="trait std::os::fd::raw::IntoRawFd">IntoRawFd</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/tcp/socket.rs.html#769-771">source</a><a href="#method.into_raw_fd" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.IntoRawFd.html#tymethod.into_raw_fd" class="fnname">into_raw_fd</a>(self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a></h4></section></summary><div class='docblock'>Consumes this object, returning the raw underlying file descriptor. <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.IntoRawFd.html#tymethod.into_raw_fd">Read more</a></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-TcpSocket" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section><section id="impl-Send-for-TcpSocket" class="impl has-srclink"><a href="#impl-Send-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section><section id="impl-Sync-for-TcpSocket" class="impl has-srclink"><a href="#impl-Sync-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section><section id="impl-Unpin-for-TcpSocket" class="impl has-srclink"><a href="#impl-Unpin-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></h3></section><section id="impl-UnwindSafe-for-TcpSocket" class="impl has-srclink"><a href="#impl-UnwindSafe-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.TcpSocket.html" title="struct tokio::net::TcpSocket">TcpSocket</a></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-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#200">source</a><a href="#impl-Any-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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 class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#201">source</a><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><a href="#impl-Borrow%3CT%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220">source</a><a href="#impl-BorrowMut%3CT%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#733">source</a><a href="#impl-From%3CT%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#736">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" 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-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#717">source</a><a href="#impl-Into%3CU%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#725">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" 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><a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="From">From</a>&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-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><a href="#impl-TryFrom%3CU%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&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 href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#781">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&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-TcpSocket" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#760">source</a><a href="#impl-TryInto%3CU%3E-for-TcpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&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 href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#766">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&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="tokio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>