1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 21:04:35 +01:00
actix-net/actix_rt/net/struct.UdpSocket.html

1030 lines
139 KiB
HTML
Raw Permalink Normal View History

<!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 UDP socket."><title>UdpSocket in actix_rt::net - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></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" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">UdpSocket</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#streams" title="Streams">Streams</a></li><li><a href="#example-one-to-many-bind" title="Example: one to many (bind)">Example: one to many (bind)</a></li><li><a href="#example-one-to-one-connect" title="Example: one to one (connect)">Example: one to one (connect)</a></li><li><a href="#example-splitting-with-arc" title="Example: Splitting with `Arc`">Example: Splitting with <code>Arc</code></a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.async_io" title="async_io">async_io</a></li><li><a href="#method.bind" title="bind">bind</a></li><li><a href="#method.bind_device" title="bind_device">bind_device</a></li><li><a href="#method.broadcast" title="broadcast">broadcast</a></li><li><a href="#method.connect" title="connect">connect</a></li><li><a href="#method.device" title="device">device</a></li><li><a href="#method.from_std" title="from_std">from_std</a></li><li><a href="#method.into_std" title="into_std">into_std</a></li><li><a href="#method.join_multicast_v4" title="join_multicast_v4">join_multicast_v4</a></li><li><a href="#method.join_multicast_v6" title="join_multicast_v6">join_multicast_v6</a></li><li><a href="#method.leave_multicast_v4" title="leave_multicast_v4">leave_multicast_v4</a></li><li><a href="#method.leave_multicast_v6" title="leave_multicast_v6">leave_multicast_v6</a></li><li><a href="#method.local_addr" title="local_addr">local_addr</a></li><li><a href="#method.multicast_loop_v4" title="multicast_loop_v4">multicast_loop_v4</a></li><li><a href="#method.multicast_loop_v6" title="multicast_loop_v6">multicast_loop_v6</a></li><li><a href="#method.multicast_ttl_v4" title="multicast_ttl_v4">multicast_ttl_v4</a></li><li><a href
<p>UDP is “connectionless”, unlike TCP. Meaning, regardless of what address youve bound to, a <code>UdpSocket</code>
is free to communicate with many different remotes. In tokio there are basically two main ways to use <code>UdpSocket</code>:</p>
<ul>
<li>one to many: <a href="struct.UdpSocket.html#method.bind" title="associated function actix_rt::net::UdpSocket::bind"><code>bind</code></a> and use <a href="struct.UdpSocket.html#method.send_to" title="method actix_rt::net::UdpSocket::send_to"><code>send_to</code></a>
and <a href="struct.UdpSocket.html#method.recv_from" title="method actix_rt::net::UdpSocket::recv_from"><code>recv_from</code></a> to communicate with many different addresses</li>
<li>one to one: <a href="struct.UdpSocket.html#method.connect" title="method actix_rt::net::UdpSocket::connect"><code>connect</code></a> and associate with a single address, using <a href="struct.UdpSocket.html#method.send" title="method actix_rt::net::UdpSocket::send"><code>send</code></a>
and <a href="struct.UdpSocket.html#method.recv" title="method actix_rt::net::UdpSocket::recv"><code>recv</code></a> to communicate only with that remote address</li>
</ul>
<p>This type does not provide a <code>split</code> method, because this functionality
can be achieved by instead wrapping the socket in an <a href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc"><code>Arc</code></a>. Note that
you do not need a <code>Mutex</code> to share the <code>UdpSocket</code> — an <code>Arc&lt;UdpSocket&gt;</code>
is enough. This is because all of the methods take <code>&amp;self</code> instead of
<code>&amp;mut self</code>. Once you have wrapped it in an <code>Arc</code>, you can call
<code>.clone()</code> on the <code>Arc&lt;UdpSocket&gt;</code> to get multiple shared handles to the
same socket. An example of such usage can be found further down.</p>
<h2 id="streams"><a class="doc-anchor" href="#streams">§</a>Streams</h2>
<p>If you need to listen over UDP and produce a <a href="https://docs.rs/futures/0.3/futures/stream/trait.Stream.html"><code>Stream</code></a>, you can look
at <a href="https://docs.rs/tokio-util/latest/tokio_util/udp/struct.UdpFramed.html"><code>UdpFramed</code></a>.</p>
<h2 id="example-one-to-many-bind"><a class="doc-anchor" href="#example-one-to-many-bind">§</a>Example: one to many (bind)</h2>
<p>Using <code>bind</code> we can create a simple echo server that sends and recvs with many different clients:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">loop </span>{
<span class="kw">let </span>(len, addr) = sock.recv_from(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?} bytes received from {:?}"</span>, len, addr);
<span class="kw">let </span>len = sock.send_to(<span class="kw-2">&amp;</span>buf[..len], addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?} bytes sent"</span>, len);
}
}</code></pre></div>
<h2 id="example-one-to-one-connect"><a class="doc-anchor" href="#example-one-to-one-connect">§</a>Example: one to one (connect)</h2>
<p>Or using <code>connect</code> we can echo with a single remote address using <code>send</code> and <code>recv</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>remote_addr = <span class="string">"127.0.0.1:59611"</span>;
sock.connect(remote_addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">loop </span>{
<span class="kw">let </span>len = sock.recv(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?} bytes received from {:?}"</span>, len, remote_addr);
<span class="kw">let </span>len = sock.send(<span class="kw-2">&amp;</span>buf[..len]).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?} bytes sent"</span>, len);
}
}</code></pre></div>
<h2 id="example-splitting-with-arc"><a class="doc-anchor" href="#example-splitting-with-arc">§</a>Example: Splitting with <code>Arc</code></h2>
<p>Because <code>send_to</code> and <code>recv_from</code> take <code>&amp;self</code>. Its perfectly alright
to use an <code>Arc&lt;UdpSocket&gt;</code> and share the references to multiple tasks.
Here is a similar “echo” example that supports concurrent
sending/receiving:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::{net::UdpSocket, sync::mpsc};
<span class="kw">use </span>std::{io, net::SocketAddr, sync::Arc};
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>.parse::&lt;SocketAddr&gt;().unwrap()).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>r = Arc::new(sock);
<span class="kw">let </span>s = r.clone();
<span class="kw">let </span>(tx, <span class="kw-2">mut </span>rx) = mpsc::channel::&lt;(Vec&lt;u8&gt;, SocketAddr)&gt;(<span class="number">1_000</span>);
tokio::spawn(<span class="kw">async move </span>{
<span class="kw">while let </span><span class="prelude-val">Some</span>((bytes, addr)) = rx.recv().<span class="kw">await </span>{
<span class="kw">let </span>len = s.send_to(<span class="kw-2">&amp;</span>bytes, <span class="kw-2">&amp;</span>addr).<span class="kw">await</span>.unwrap();
<span class="macro">println!</span>(<span class="string">"{:?} bytes sent"</span>, len);
}
});
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">loop </span>{
<span class="kw">let </span>(len, addr) = r.recv_from(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?} bytes received from {:?}"</span>, len, addr);
tx.send((buf[..len].to_vec(), addr)).<span class="kw">await</span>.unwrap();
}
}</code></pre></div>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-UdpSocket" class="impl"><a href="#impl-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.bind" class="method"><h4 class="code-header">pub async fn <a href="#method.bind" class="fn">bind</a>&lt;A&gt;(addr: A) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a>, <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;<div class="where">where
A: ToSocketAddrs,</div></h4></section></summary><div class="docblock"><p>This function will create a new UDP socket and attempt to bind it to
the <code>addr</code> provided.</p>
<p>Binding with a port number of 0 will request that the OS assigns a port
to this listener. The port allocated can be queried via the <code>local_addr</code>
method.</p>
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// use `sock`
</span><span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_std" class="method"><h4 class="code-header">pub fn <a href="#method.from_std" class="fn">from_std</a>(socket: <a class="struct" href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a>, <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;</h4></section></summary><div class="docblock"><p>Creates new <code>UdpSocket</code> from a previously bound <code>std::net::UdpSocket</code>.</p>
<p>This function is intended to be used to wrap a UDP socket from the
standard library in the Tokio equivalent.</p>
<p>This can be used in conjunction with <code>socket2</code>s <code>Socket</code> interface to
configure a socket before its handed off, such as setting options like
<code>reuse_address</code> or binding to multiple addresses.</p>
<h5 id="notes"><a class="doc-anchor" href="#notes">§</a>Notes</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/udp/struct.UdpSocket.html#method.set_nonblocking" title="method std::net::udp::UdpSocket::set_nonblocking"><code>set_nonblocking</code></a>.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>This function panics if thread-local runtime is not set.</p>
<p>The runtime is usually set implicitly when this function is called
from a future driven by a tokio runtime, otherwise runtime can be set
explicitly with <a href="crate::runtime::Runtime::enter"><code>Runtime::enter</code></a> function.</p>
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>addr = <span class="string">"0.0.0.0:8080"</span>.parse::&lt;SocketAddr&gt;().unwrap();
<span class="kw">let </span>std_sock = std::net::UdpSocket::bind(addr)<span class="question-mark">?</span>;
std_sock.set_nonblocking(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>sock = UdpSocket::from_std(std_sock)<span class="question-mark">?</span>;
<span class="comment">// use `sock`</span></code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.into_std" class="method"><h4 class="code-header">pub fn <a href="#method.into_std" class="fn">into_std</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;<a class="struct" href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a>, <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;</h4></section></summary><div class="docblock"><p>Turns a <a href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket"><code>tokio::net::UdpSocket</code></a> into a <a href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket"><code>std::net::UdpSocket</code></a>.</p>
<p>The returned <a href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket"><code>std::net::UdpSocket</code></a> will have nonblocking mode set as
<code>true</code>. Use <a href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html#method.set_nonblocking" title="method std::net::udp::UdpSocket::set_nonblocking"><code>set_nonblocking</code></a> to change the blocking mode if needed.</p>
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::error::Error;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="kw">let </span>tokio_socket = tokio::net::UdpSocket::bind(<span class="string">"127.0.0.1:0"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>std_socket = tokio_socket.into_std()<span class="question-mark">?</span>;
std_socket.set_nonblocking(<span class="bool-val">false</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.local_addr" class="method"><h4 class="code-header">pub fn <a href="#method.local_addr" class="fn">local_addr</a>(&amp;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;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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;</h4></section></summary><div class="docblock"><p>Returns the local address that this socket is bound to.</p>
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>addr = <span class="string">"0.0.0.0:8080"</span>.parse::&lt;SocketAddr&gt;().unwrap();
<span class="kw">let </span>sock = UdpSocket::bind(addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// the address the socket is bound to
</span><span class="kw">let </span>local_addr = sock.local_addr()<span class="question-mark">?</span>;</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.peer_addr" class="method"><h4 class="code-header">pub fn <a href="#method.peer_addr" class="fn">peer_addr</a>(&amp;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;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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;</h4></section></summary><div class="docblock"><p>Returns the socket address of the remote peer this socket was connected to.</p>
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>addr = <span class="string">"0.0.0.0:8080"</span>.parse::&lt;SocketAddr&gt;().unwrap();
<span class="kw">let </span>peer = <span class="string">"127.0.0.1:11100"</span>.parse::&lt;SocketAddr&gt;().unwrap();
<span class="kw">let </span>sock = UdpSocket::bind(addr).<span class="kw">await</span><span class="question-mark">?</span>;
sock.connect(peer).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(peer, sock.peer_addr()<span class="question-mark">?</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.connect" class="method"><h4 class="code-header">pub async fn <a href="#method.connect" class="fn">connect</a>&lt;A&gt;(&amp;self, addr: A) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;<div class="where">where
A: ToSocketAddrs,</div></h4></section></summary><div class="docblock"><p>Connects the UDP socket setting the default destination for send() and
limiting packets that are read via <code>recv</code> from the address specified in
<code>addr</code>.</p>
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>.parse::&lt;SocketAddr&gt;().unwrap()).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>remote_addr = <span class="string">"127.0.0.1:59600"</span>.parse::&lt;SocketAddr&gt;().unwrap();
sock.connect(remote_addr).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0u8</span>; <span class="number">32</span>];
<span class="comment">// recv from remote_addr
</span><span class="kw">let </span>len = sock.recv(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// send to remote_addr
</span><span class="kw">let </span>_len = sock.send(<span class="kw-2">&amp;</span>buf[..len]).<span class="kw">await</span><span class="question-mark">?</span>;</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.ready" class="method"><h4 class="code-header">pub async fn <a href="#method.ready" class="fn">ready</a>(&amp;self, interest: Interest) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.Ready.html" title="struct actix_rt::net::Ready">Ready</a>, <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;</h4></section></summary><div class="docblock"><p>Waits for any of the requested ready states.</p>
<p>This function is usually paired with <code>try_recv()</code> or <code>try_send()</code>. It
can be used to concurrently <code>recv</code> / <code>send</code> to the same socket on a single
task without splitting the socket.</p>
<p>The function may complete without the socket being ready. This is a
false-positive and attempting an operation will return with
<code>io::ErrorKind::WouldBlock</code>. The function can also return with an empty
<a href="struct.Ready.html" title="struct actix_rt::net::Ready"><code>Ready</code></a> set, so you should always check the returned value and possibly
wait again if the requested states are not set.</p>
<h5 id="cancel-safety"><a class="doc-anchor" href="#cancel-safety">§</a>Cancel safety</h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to read or write that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</p>
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
<p>Concurrently receive from and send to the socket on the same task
without splitting.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, Interest};
<span class="kw">use </span>tokio::net::UdpSocket;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="kw">let </span>ready = socket.ready(Interest::READABLE | Interest::WRITABLE).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">if </span>ready.is_readable() {
<span class="comment">// The buffer is **not** included in the async task and will only exist
// on the stack.
</span><span class="kw">let </span><span class="kw-2">mut </span>data = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">match </span>socket.try_recv(<span class="kw-2">&amp;mut </span>data[..]) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">"received {:?}"</span>, <span class="kw-2">&amp;</span>data[..n]);
}
<span class="comment">// False-positive, continue
</span><span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="kw">if </span>ready.is_writable() {
<span class="comment">// Write some data
</span><span class="kw">match </span>socket.try_send(<span class="string">b"hello world"</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">"sent {} bytes"</span>, n);
}
<span class="comment">// False-positive, continue
</span><span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
}
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.writable" class="method"><h4 class="code-header">pub async fn <a href="#method.writable" class="fn">writable</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Waits for the socket to become writable.</p>
<p>This function is equivalent to <code>ready(Interest::WRITABLE)</code> and is
usually paired with <code>try_send()</code> or <code>try_send_to()</code>.</p>
<p>The function may complete without the socket being writable. This is a
false-positive and attempting a <code>try_send()</code> will return with
<code>io::ErrorKind::WouldBlock</code>.</p>
<h5 id="cancel-safety-1"><a class="doc-anchor" href="#cancel-safety-1">§</a>Cancel safety</h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to write that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</p>
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Bind socket
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be writable
</span>socket.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to send data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>socket.try_send(<span class="string">b"hello world"</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_send_ready" class="method"><h4 class="code-header">pub fn <a href="#method.poll_send_ready" class="fn">poll_send_ready</a>(&amp;self, cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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>Polls for write/send readiness.</p>
<p>If the udp stream is not currently ready for sending, this method will
store a clone of the <code>Waker</code> from the provided <code>Context</code>. When the udp
stream becomes ready for sending, <code>Waker::wake</code> will be called on the
waker.</p>
<p>Note that on multiple calls to <code>poll_send_ready</code> or <code>poll_send</code>, only
the <code>Waker</code> from the <code>Context</code> passed to the most recent call is
scheduled to receive a wakeup. (However, <code>poll_recv_ready</code> retains a
second, independent waker.)</p>
<p>This function is intended for cases where creating and pinning a future
via <a href="struct.UdpSocket.html#method.writable" title="method actix_rt::net::UdpSocket::writable"><code>writable</code></a> is not feasible. Where possible, using <a href="struct.UdpSocket.html#method.writable" title="method actix_rt::net::UdpSocket::writable"><code>writable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<h5 id="return-value"><a class="doc-anchor" href="#return-value">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the udp stream is not ready for writing.</li>
<li><code>Poll::Ready(Ok(()))</code> if the udp stream is ready for writing.</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.send" class="method"><h4 class="code-header">pub async fn <a href="#method.send" class="fn">send</a>(&amp;self, buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;</h4></section></summary><div class="docblock"><p>Sends data on the socket to the remote address that the socket is
connected to.</p>
<p>The <a href="struct.UdpSocket.html#method.connect" title="method actix_rt::net::UdpSocket::connect"><code>connect</code></a> method will connect this socket to a remote address.
This method will fail if the socket is not connected.</p>
<h5 id="return"><a class="doc-anchor" href="#return">§</a>Return</h5>
<p>On success, the number of bytes sent is returned, otherwise, the
encountered error is returned.</p>
<h5 id="cancel-safety-2"><a class="doc-anchor" href="#cancel-safety-2">§</a>Cancel safety</h5>
<p>This method is cancel safe. If <code>send</code> is used as the event in a
<a href="crate::select"><code>tokio::select!</code></a> statement and some other branch
completes first, then it is guaranteed that the message was not sent.</p>
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io;
<span class="kw">use </span>tokio::net::UdpSocket;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Bind socket
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Send a message
</span>socket.send(<span class="string">b"hello world"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_send" class="method"><h4 class="code-header">pub fn <a href="#method.poll_send" class="fn">poll_send</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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>Attempts to send data on the socket to the remote address to which it
was previously <code>connect</code>ed.</p>
<p>The <a href="struct.UdpSocket.html#method.connect" title="method actix_rt::net::UdpSocket::connect"><code>connect</code></a> method will connect this socket to a remote address.
This method will fail if the socket is not connected.</p>
<p>Note that on multiple calls to a <code>poll_*</code> method in the send direction,
only the <code>Waker</code> from the <code>Context</code> passed to the most recent call will
be scheduled to receive a wakeup.</p>
<h5 id="return-value-1"><a class="doc-anchor" href="#return-value-1">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the socket is not available to write</li>
<li><code>Poll::Ready(Ok(n))</code> <code>n</code> is the number of bytes sent</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-1"><a class="doc-anchor" href="#errors-1">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_send" class="method"><h4 class="code-header">pub fn <a href="#method.try_send" class="fn">try_send</a>(&amp;self, buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;</h4></section></summary><div class="docblock"><p>Tries to send data on the socket to the remote address to which it is
connected.</p>
<p>When the socket buffer is full, <code>Err(io::ErrorKind::WouldBlock)</code> is
returned. This function is usually paired with <code>writable()</code>.</p>
<h5 id="returns"><a class="doc-anchor" href="#returns">§</a>Returns</h5>
<p>If successful, <code>Ok(n)</code> is returned, where <code>n</code> is the number of bytes
sent. If the socket is not ready to send data,
<code>Err(ErrorKind::WouldBlock)</code> is returned.</p>
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Bind a UDP socket
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Connect to a peer
</span>socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be writable
</span>socket.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to send data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>socket.try_send(<span class="string">b"hello world"</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.readable" class="method"><h4 class="code-header">pub async fn <a href="#method.readable" class="fn">readable</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Waits for the socket to become readable.</p>
<p>This function is equivalent to <code>ready(Interest::READABLE)</code> and is usually
paired with <code>try_recv()</code>.</p>
<p>The function may complete without the socket being readable. This is a
false-positive and attempting a <code>try_recv()</code> will return with
<code>io::ErrorKind::WouldBlock</code>.</p>
<h5 id="cancel-safety-3"><a class="doc-anchor" href="#cancel-safety-3">§</a>Cancel safety</h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to read that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</p>
<h5 id="examples-5"><a class="doc-anchor" href="#examples-5">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>socket.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// The buffer is **not** included in the async task and will
// only exist on the stack.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="comment">// Try to recv data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>socket.try_recv(<span class="kw-2">&amp;mut </span>buf) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">"GOT {:?}"</span>, <span class="kw-2">&amp;</span>buf[..n]);
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_recv_ready" class="method"><h4 class="code-header">pub fn <a href="#method.poll_recv_ready" class="fn">poll_recv_ready</a>(&amp;self, cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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>Polls for read/receive readiness.</p>
<p>If the udp stream is not currently ready for receiving, this method will
store a clone of the <code>Waker</code> from the provided <code>Context</code>. When the udp
socket becomes ready for reading, <code>Waker::wake</code> will be called on the
waker.</p>
<p>Note that on multiple calls to <code>poll_recv_ready</code>, <code>poll_recv</code> or
<code>poll_peek</code>, only the <code>Waker</code> from the <code>Context</code> passed to the most
recent call is scheduled to receive a wakeup. (However,
<code>poll_send_ready</code> retains a second, independent waker.)</p>
<p>This function is intended for cases where creating and pinning a future
via <a href="struct.UdpSocket.html#method.readable" title="method actix_rt::net::UdpSocket::readable"><code>readable</code></a> is not feasible. Where possible, using <a href="struct.UdpSocket.html#method.readable" title="method actix_rt::net::UdpSocket::readable"><code>readable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<h5 id="return-value-2"><a class="doc-anchor" href="#return-value-2">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the udp stream is not ready for reading.</li>
<li><code>Poll::Ready(Ok(()))</code> if the udp stream is ready for reading.</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-2"><a class="doc-anchor" href="#errors-2">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.recv" class="method"><h4 class="code-header">pub async fn <a href="#method.recv" class="fn">recv</a>(&amp;self, buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;</h4></section></summary><div class="docblock"><p>Receives a single datagram message on the socket from the remote address
to which it is connected. On success, returns the number of bytes read.</p>
<p>The function must be called with valid byte array <code>buf</code> of sufficient
size to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.</p>
<p>The <a href="struct.UdpSocket.html#method.connect" title="method actix_rt::net::UdpSocket::connect"><code>connect</code></a> method will connect this socket to a remote address.
This method will fail if the socket is not connected.</p>
<h5 id="cancel-safety-4"><a class="doc-anchor" href="#cancel-safety-4">§</a>Cancel safety</h5>
<p>This method is cancel safe. If <code>recv</code> is used as the event in a
<a href="crate::select"><code>tokio::select!</code></a> statement and some other branch
completes first, it is guaranteed that no messages were received on this
socket.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Bind socket
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">10</span>];
<span class="kw">let </span>n = socket.recv(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"received {} bytes {:?}"</span>, n, <span class="kw-2">&amp;</span>buf[..n]);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_recv" class="method"><h4 class="code-header">pub fn <a href="#method.poll_recv" class="fn">poll_recv</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
buf: &amp;mut ReadBuf&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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>Attempts to receive a single datagram message on the socket from the remote
address to which it is <code>connect</code>ed.</p>
<p>The <a href="struct.UdpSocket.html#method.connect" title="method actix_rt::net::UdpSocket::connect"><code>connect</code></a> method will connect this socket to a remote address. This method
resolves to an error if the socket is not connected.</p>
<p>Note that on multiple calls to a <code>poll_*</code> method in the <code>recv</code> direction, only the
<code>Waker</code> from the <code>Context</code> passed to the most recent call will be scheduled to
receive a wakeup.</p>
<h5 id="return-value-3"><a class="doc-anchor" href="#return-value-3">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the socket is not ready to read</li>
<li><code>Poll::Ready(Ok(()))</code> reads data <code>ReadBuf</code> if the socket is ready</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-3"><a class="doc-anchor" href="#errors-3">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_recv" class="method"><h4 class="code-header">pub fn <a href="#method.try_recv" class="fn">try_recv</a>(&amp;self, buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;</h4></section></summary><div class="docblock"><p>Tries to receive a single datagram message on the socket from the remote
address to which it is connected. On success, returns the number of
bytes read.</p>
<p>This method must be called with valid byte array <code>buf</code> of sufficient size
to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.</p>
<p>When there is no pending data, <code>Err(io::ErrorKind::WouldBlock)</code> is
returned. This function is usually paired with <code>readable()</code>.</p>
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
socket.connect(<span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>socket.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// The buffer is **not** included in the async task and will
// only exist on the stack.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="comment">// Try to recv data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>socket.try_recv(<span class="kw-2">&amp;mut </span>buf) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">"GOT {:?}"</span>, <span class="kw-2">&amp;</span>buf[..n]);
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.send_to" class="method"><h4 class="code-header">pub async fn <a href="#method.send_to" class="fn">send_to</a>&lt;A&gt;(&amp;self, buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>], target: A) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;<div class="where">where
A: ToSocketAddrs,</div></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>Address type can be any implementor of <a href="crate::net::ToSocketAddrs"><code>ToSocketAddrs</code></a> trait. See its
documentation for concrete examples.</p>
<p>It is possible for <code>addr</code> to yield multiple addresses, but <code>send_to</code>
will only send data to the first address yielded by <code>addr</code>.</p>
<p>This will return an error when the IP version of the local socket does
not match that returned from <a href="crate::net::ToSocketAddrs"><code>ToSocketAddrs</code></a>.</p>
<h5 id="cancel-safety-5"><a class="doc-anchor" href="#cancel-safety-5">§</a>Cancel safety</h5>
<p>This method is cancel safe. If <code>send_to</code> is used as the event in a
<a href="crate::select"><code>tokio::select!</code></a> statement and some other branch
completes first, then it is guaranteed that the message was not sent.</p>
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>len = socket.send_to(<span class="string">b"hello world"</span>, <span class="string">"127.0.0.1:8081"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"Sent {} bytes"</span>, len);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_send_to" class="method"><h4 class="code-header">pub fn <a href="#method.poll_send_to" class="fn">poll_send_to</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
target: <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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>Attempts to send data on the socket to a given address.</p>
<p>Note that on multiple calls to a <code>poll_*</code> method in the send direction, only the
<code>Waker</code> from the <code>Context</code> passed to the most recent call will be scheduled to
receive a wakeup.</p>
<h5 id="return-value-4"><a class="doc-anchor" href="#return-value-4">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the socket is not ready to write</li>
<li><code>Poll::Ready(Ok(n))</code> <code>n</code> is the number of bytes sent.</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-4"><a class="doc-anchor" href="#errors-4">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_send_to" class="method"><h4 class="code-header">pub fn <a href="#method.try_send_to" class="fn">try_send_to</a>(
&amp;self,
buf: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
target: <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <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;</h4></section></summary><div class="docblock"><p>Tries to send data on the socket to the given address, but if the send is
blocked this will return right away.</p>
<p>This function is usually paired with <code>writable()</code>.</p>
<h5 id="returns-1"><a class="doc-anchor" href="#returns-1">§</a>Returns</h5>
<p>If successful, returns the number of bytes sent</p>
<p>Users should ensure that when the remote cannot receive, the
<a href="https://doc.rust-lang.org/nightly/std/io/error/enum.ErrorKind.html#variant.WouldBlock" title="variant std::io::error::ErrorKind::WouldBlock"><code>ErrorKind::WouldBlock</code></a> is properly handled. An error can also occur
if the IP version of the socket does not match that of <code>target</code>.</p>
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>dst = <span class="string">"127.0.0.1:8081"</span>.parse()<span class="question-mark">?</span>;
<span class="kw">loop </span>{
socket.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match </span>socket.try_send_to(<span class="kw-2">&amp;</span><span class="string">b"hello world"</span>[..], dst) {
<span class="prelude-val">Ok</span>(sent) =&gt; {
<span class="macro">println!</span>(<span class="string">"sent {} bytes"</span>, sent);
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="comment">// Writable false positive.
</span><span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; <span class="kw">return </span><span class="prelude-val">Err</span>(e.into()),
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.recv_from" class="method"><h4 class="code-header">pub async fn <a href="#method.recv_from" class="fn">recv_from</a>(
&amp;self,
buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>), <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;</h4></section></summary><div class="docblock"><p>Receives a single datagram message on the socket. On success, returns
the number of bytes read and the origin.</p>
<p>The function must be called with valid byte array <code>buf</code> of sufficient
size to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.</p>
<h5 id="cancel-safety-6"><a class="doc-anchor" href="#cancel-safety-6">§</a>Cancel safety</h5>
<p>This method is cancel safe. If <code>recv_from</code> is used as the event in a
<a href="crate::select"><code>tokio::select!</code></a> statement and some other branch
completes first, it is guaranteed that no messages were received on this
socket.</p>
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[<span class="number">0u8</span>; <span class="number">32</span>];
<span class="kw">let </span>(len, addr) = socket.recv_from(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"received {:?} bytes from {:?}"</span>, len, addr);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
<h5 id="notes-1"><a class="doc-anchor" href="#notes-1">§</a>Notes</h5>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_recv_from" class="method"><h4 class="code-header">pub fn <a href="#method.poll_recv_from" class="fn">poll_recv_from</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
buf: &amp;mut ReadBuf&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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>Attempts to receive a single datagram on the socket.</p>
<p>Note that on multiple calls to a <code>poll_*</code> method in the <code>recv</code> direction, only the
<code>Waker</code> from the <code>Context</code> passed to the most recent call will be scheduled to
receive a wakeup.</p>
<h5 id="return-value-5"><a class="doc-anchor" href="#return-value-5">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the socket is not ready to read</li>
<li><code>Poll::Ready(Ok(addr))</code> reads data from <code>addr</code> into <code>ReadBuf</code> if the socket is ready</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-5"><a class="doc-anchor" href="#errors-5">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
<h5 id="notes-2"><a class="doc-anchor" href="#notes-2">§</a>Notes</h5>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_recv_from" class="method"><h4 class="code-header">pub fn <a href="#method.try_recv_from" class="fn">try_recv_from</a>(
&amp;self,
buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>), <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;</h4></section></summary><div class="docblock"><p>Tries to receive a single datagram message on the socket. On success,
returns the number of bytes read and the origin.</p>
<p>This method must be called with valid byte array <code>buf</code> of sufficient size
to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.</p>
<p>When there is no pending data, <code>Err(io::ErrorKind::WouldBlock)</code> is
returned. This function is usually paired with <code>readable()</code>.</p>
<h5 id="notes-3"><a class="doc-anchor" href="#notes-3">§</a>Notes</h5>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>socket.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// The buffer is **not** included in the async task and will
// only exist on the stack.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="comment">// Try to recv data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>socket.try_recv_from(<span class="kw-2">&amp;mut </span>buf) {
<span class="prelude-val">Ok</span>((n, _addr)) =&gt; {
<span class="macro">println!</span>(<span class="string">"GOT {:?}"</span>, <span class="kw-2">&amp;</span>buf[..n]);
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e);
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_io" class="method"><h4 class="code-header">pub fn <a href="#method.try_io" class="fn">try_io</a>&lt;R&gt;(
&amp;self,
interest: Interest,
f: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>() -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <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; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <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;</h4></section></summary><div class="docblock"><p>Tries to read or write from the socket using a user-provided IO operation.</p>
<p>If the socket is ready, the provided closure is called. The closure
should attempt to perform IO operation on the socket by manually
calling the appropriate syscall. If the operation fails because the
socket is not actually ready, then the closure should return a
<code>WouldBlock</code> error and the readiness flag is cleared. The return value
of the closure is then returned by <code>try_io</code>.</p>
<p>If the socket is not ready, then the closure is not called
and a <code>WouldBlock</code> error is returned.</p>
<p>The closure should only return a <code>WouldBlock</code> error if it has performed
an IO operation on the socket that failed due to the socket not being
ready. Returning a <code>WouldBlock</code> error in any other situation will
incorrectly clear the readiness flag, which can cause the socket to
behave incorrectly.</p>
<p>The closure should not perform the IO operation using any of the methods
defined on the Tokio <code>UdpSocket</code> type, as this will mess with the
readiness flag and can cause the socket to behave incorrectly.</p>
<p>This method is not intended to be used with combined interests.
The closure should perform only one type of IO operation, so it should not
require more than one ready state. This method may panic or sleep forever
if it is called with a combined interest.</p>
<p>Usually, <a href="struct.UdpSocket.html#method.readable" title="method actix_rt::net::UdpSocket::readable"><code>readable()</code></a>, <a href="struct.UdpSocket.html#method.writable" title="method actix_rt::net::UdpSocket::writable"><code>writable()</code></a> or <a href="struct.UdpSocket.html#method.ready" title="method actix_rt::net::UdpSocket::ready"><code>ready()</code></a> is used with this function.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.async_io" class="method"><h4 class="code-header">pub async fn <a href="#method.async_io" class="fn">async_io</a>&lt;R&gt;(
&amp;self,
interest: Interest,
f: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>() -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <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; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;R, <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;</h4></section></summary><div class="docblock"><p>Reads or writes from the socket using a user-provided IO operation.</p>
<p>The readiness of the socket is awaited and when the socket is ready,
the provided closure is called. The closure should attempt to perform
IO operation on the socket by manually calling the appropriate syscall.
If the operation fails because the socket is not actually ready,
then the closure should return a <code>WouldBlock</code> error. In such case the
readiness flag is cleared and the socket readiness is awaited again.
This loop is repeated until the closure returns an <code>Ok</code> or an error
other than <code>WouldBlock</code>.</p>
<p>The closure should only return a <code>WouldBlock</code> error if it has performed
an IO operation on the socket that failed due to the socket not being
ready. Returning a <code>WouldBlock</code> error in any other situation will
incorrectly clear the readiness flag, which can cause the socket to
behave incorrectly.</p>
<p>The closure should not perform the IO operation using any of the methods
defined on the Tokio <code>UdpSocket</code> type, as this will mess with the
readiness flag and can cause the socket to behave incorrectly.</p>
<p>This method is not intended to be used with combined interests.
The closure should perform only one type of IO operation, so it should not
require more than one ready state. This method may panic or sleep forever
if it is called with a combined interest.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek_from" class="method"><h4 class="code-header">pub async fn <a href="#method.peek_from" class="fn">peek_from</a>(
&amp;self,
buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>), <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;</h4></section></summary><div class="docblock"><p>Receives data from the socket, without removing it from the input queue.
On success, returns the number of bytes read and the address from whence
the data came.</p>
<h5 id="notes-4"><a class="doc-anchor" href="#notes-4">§</a>Notes</h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and <code>peek_from</code> returns the error
<code>WSAEMSGSIZE(10040)</code>. The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
<p>MacOS will return an error if you pass a zero-sized buffer.</p>
<p>If youre merely interested in learning the sender of the data at the head of the queue,
try <a href="struct.UdpSocket.html#method.peek_sender" title="method actix_rt::net::UdpSocket::peek_sender"><code>peek_sender</code></a>.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[<span class="number">0u8</span>; <span class="number">32</span>];
<span class="kw">let </span>(len, addr) = socket.peek_from(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"peeked {:?} bytes from {:?}"</span>, len, addr);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_peek_from" class="method"><h4 class="code-header">pub fn <a href="#method.poll_peek_from" class="fn">poll_peek_from</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
buf: &amp;mut ReadBuf&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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>Receives data from the socket, without removing it from the input queue.
On success, returns the sending address of the datagram.</p>
<h5 id="notes-5"><a class="doc-anchor" href="#notes-5">§</a>Notes</h5>
<p>Note that on multiple calls to a <code>poll_*</code> method in the <code>recv</code> direction, only the
<code>Waker</code> from the <code>Context</code> passed to the most recent call will be scheduled to
receive a wakeup</p>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and peek returns the error
<code>WSAEMSGSIZE(10040)</code>. The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
<p>MacOS will return an error if you pass a zero-sized buffer.</p>
<p>If youre merely interested in learning the sender of the data at the head of the queue,
try <a href="struct.UdpSocket.html#method.poll_peek_sender" title="method actix_rt::net::UdpSocket::poll_peek_sender"><code>poll_peek_sender</code></a>.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
<h5 id="return-value-6"><a class="doc-anchor" href="#return-value-6">§</a>Return value</h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the socket is not ready to read</li>
<li><code>Poll::Ready(Ok(addr))</code> reads data from <code>addr</code> into <code>ReadBuf</code> if the socket is ready</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-6"><a class="doc-anchor" href="#errors-6">§</a>Errors</h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_peek_from" class="method"><h4 class="code-header">pub fn <a href="#method.try_peek_from" class="fn">try_peek_from</a>(
&amp;self,
buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>), <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;</h4></section></summary><div class="docblock"><p>Tries to receive data on the socket without removing it from the input queue.
On success, returns the number of bytes read and the sending address of the
datagram.</p>
<p>When there is no pending data, <code>Err(io::ErrorKind::WouldBlock)</code> is
returned. This function is usually paired with <code>readable()</code>.</p>
<h5 id="notes-6"><a class="doc-anchor" href="#notes-6">§</a>Notes</h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and peek returns the error
<code>WSAEMSGSIZE(10040)</code>. The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
<p>MacOS will return an error if you pass a zero-sized buffer.</p>
<p>If youre merely interested in learning the sender of the data at the head of the queue,
try <a href="struct.UdpSocket.html#method.try_peek_sender" title="method actix_rt::net::UdpSocket::try_peek_sender"><code>try_peek_sender</code></a>.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek_sender" class="method"><h4 class="code-header">pub async fn <a href="#method.peek_sender" class="fn">peek_sender</a>(&amp;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;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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;</h4></section></summary><div class="docblock"><p>Retrieve the sender of the data at the head of the input queue, waiting if empty.</p>
<p>This is equivalent to calling <a href="struct.UdpSocket.html#method.peek_from" title="method actix_rt::net::UdpSocket::peek_from"><code>peek_from</code></a> with a zero-sized buffer,
but suppresses the <code>WSAEMSGSIZE</code> error on Windows and the “invalid argument” error on macOS.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.poll_peek_sender" class="method"><h4 class="code-header">pub fn <a href="#method.poll_peek_sender" class="fn">poll_peek_sender</a>(
&amp;self,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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>Retrieve the sender of the data at the head of the input queue,
scheduling a wakeup if empty.</p>
<p>This is equivalent to calling <a href="struct.UdpSocket.html#method.poll_peek_from" title="method actix_rt::net::UdpSocket::poll_peek_from"><code>poll_peek_from</code></a> with a zero-sized buffer,
but suppresses the <code>WSAEMSGSIZE</code> error on Windows and the “invalid argument” error on macOS.</p>
<h5 id="notes-7"><a class="doc-anchor" href="#notes-7">§</a>Notes</h5>
<p>Note that on multiple calls to a <code>poll_*</code> method in the <code>recv</code> direction, only the
<code>Waker</code> from the <code>Context</code> passed to the most recent call will be scheduled to
receive a wakeup.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_peek_sender" class="method"><h4 class="code-header">pub fn <a href="#method.try_peek_sender" class="fn">try_peek_sender</a>(&amp;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;<a class="enum" href="https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>, <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;</h4></section></summary><div class="docblock"><p>Try to retrieve the sender of the data at the head of the input queue.</p>
<p>When there is no pending data, <code>Err(io::ErrorKind::WouldBlock)</code> is
returned. This function is usually paired with <code>readable()</code>.</p>
<p>Note that the socket address <strong>cannot</strong> be implicitly trusted, because it is relatively
trivial to send a UDP datagram with a spoofed origin in a <a href="https://en.wikipedia.org/wiki/Packet_injection">packet injection attack</a>.
Because UDP is stateless and does not validate the origin of a packet,
the attacker does not need to be able to intercept traffic in order to interfere.
It is important to be aware of this when designing your application-level protocol.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.broadcast" class="method"><h4 class="code-header">pub fn <a href="#method.broadcast" class="fn">broadcast</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, <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;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>SO_BROADCAST</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.UdpSocket.html#method.set_broadcast" title="method actix_rt::net::UdpSocket::set_broadcast"><code>set_broadcast</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_broadcast" class="method"><h4 class="code-header">pub fn <a href="#method.set_broadcast" class="fn">set_broadcast</a>(&amp;self, on: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Sets 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="toggle method-toggle" open><summary><section id="method.multicast_loop_v4" class="method"><h4 class="code-header">pub fn <a href="#method.multicast_loop_v4" class="fn">multicast_loop_v4</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, <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;</h4></section></summary><div class="docblock"><p>Gets 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.UdpSocket.html#method.set_multicast_loop_v4" title="method actix_rt::net::UdpSocket::set_multicast_loop_v4"><code>set_multicast_loop_v4</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_multicast_loop_v4" class="method"><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v4" class="fn">set_multicast_loop_v4</a>(&amp;self, on: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Sets 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.</p>
<h5 id="note"><a class="doc-anchor" href="#note">§</a>Note</h5>
<p>This may not have any affect on IPv6 sockets.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.multicast_ttl_v4" class="method"><h4 class="code-header">pub fn <a href="#method.multicast_ttl_v4" class="fn">multicast_ttl_v4</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <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;</h4></section></summary><div class="docblock"><p>Gets 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.UdpSocket.html#method.set_multicast_ttl_v4" title="method actix_rt::net::UdpSocket::set_multicast_ttl_v4"><code>set_multicast_ttl_v4</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_multicast_ttl_v4" class="method"><h4 class="code-header">pub fn <a href="#method.set_multicast_ttl_v4" class="fn">set_multicast_ttl_v4</a>(&amp;self, ttl: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Sets 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
dont leave the local network unless explicitly requested.</p>
<h5 id="note-1"><a class="doc-anchor" href="#note-1">§</a>Note</h5>
<p>This may not have any affect on IPv6 sockets.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.multicast_loop_v6" class="method"><h4 class="code-header">pub fn <a href="#method.multicast_loop_v6" class="fn">multicast_loop_v6</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, <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;</h4></section></summary><div class="docblock"><p>Gets 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.UdpSocket.html#method.set_multicast_loop_v6" title="method actix_rt::net::UdpSocket::set_multicast_loop_v6"><code>set_multicast_loop_v6</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_multicast_loop_v6" class="method"><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v6" class="fn">set_multicast_loop_v6</a>(&amp;self, on: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Sets 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.</p>
<h5 id="note-2"><a class="doc-anchor" href="#note-2">§</a>Note</h5>
<p>This may not have any affect on IPv4 sockets.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.ttl" class="method"><h4 class="code-header">pub fn <a href="#method.ttl" class="fn">ttl</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <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;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IP_TTL</code> option for this socket.</p>
<p>For more information about this option, see <a href="struct.UdpSocket.html#method.set_ttl" title="method actix_rt::net::UdpSocket::set_ttl"><code>set_ttl</code></a>.</p>
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, sock.ttl()<span class="question-mark">?</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.set_ttl" class="method"><h4 class="code-header">pub fn <a href="#method.set_ttl" class="fn">set_ttl</a>(&amp;self, ttl: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Sets the value for the <code>IP_TTL</code> option on this socket.</p>
<p>This value sets the time-to-live field that is used in every packet sent
from this socket.</p>
<h5 id="examples-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">let </span>sock = UdpSocket::bind(<span class="string">"127.0.0.1:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
sock.set_ttl(<span class="number">60</span>)<span class="question-mark">?</span>;
</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.tos" class="method"><h4 class="code-header">pub fn <a href="#method.tos" class="fn">tos</a>(&amp;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;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <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;</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.UdpSocket.html#method.set_tos" title="method actix_rt::net::UdpSocket::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="toggle method-toggle" open><summary><section id="method.set_tos" class="method"><h4 class="code-header">pub fn <a href="#method.set_tos" class="fn">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="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</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="toggle method-toggle" open><summary><section id="method.device" class="method"><h4 class="code-header">pub fn <a href="#method.device" class="fn">device</a>(&amp;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;<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;, <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;</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-bound devices interface name.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.bind_device" class="method"><h4 class="code-header">pub fn <a href="#method.bind_device" class="fn">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="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</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="toggle method-toggle" open><summary><section id="method.join_multicast_v4" class="method"><h4 class="code-header">pub fn <a href="#method.join_multicast_v4" class="fn">join_multicast_v4</a>(
&amp;self,
multiaddr: <a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
interface: <a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IP_ADD_MEMBERSHIP</code> type.</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 its equal to <code>INADDR_ANY</code> then an appropriate
interface is chosen by the system.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.join_multicast_v6" class="method"><h4 class="code-header">pub fn <a href="#method.join_multicast_v6" class="fn">join_multicast_v6</a>(
&amp;self,
multiaddr: &amp;<a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv6Addr.html" title="struct core::net::ip_addr::Ipv6Addr">Ipv6Addr</a>,
interface: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IPV6_ADD_MEMBERSHIP</code> type.</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="toggle method-toggle" open><summary><section id="method.leave_multicast_v4" class="method"><h4 class="code-header">pub fn <a href="#method.leave_multicast_v4" class="fn">leave_multicast_v4</a>(
&amp;self,
multiaddr: <a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
interface: <a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IP_DROP_MEMBERSHIP</code> type.</p>
<p>For more information about this option, see <a href="struct.UdpSocket.html#method.join_multicast_v4" title="method actix_rt::net::UdpSocket::join_multicast_v4"><code>join_multicast_v4</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.leave_multicast_v6" class="method"><h4 class="code-header">pub fn <a href="#method.leave_multicast_v6" class="fn">leave_multicast_v6</a>(
&amp;self,
multiaddr: &amp;<a class="struct" href="https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv6Addr.html" title="struct core::net::ip_addr::Ipv6Addr">Ipv6Addr</a>,
interface: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <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;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IPV6_DROP_MEMBERSHIP</code> type.</p>
<p>For more information about this option, see <a href="struct.UdpSocket.html#method.join_multicast_v6" title="method actix_rt::net::UdpSocket::join_multicast_v6"><code>join_multicast_v6</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.take_error" class="method"><h4 class="code-header">pub fn <a href="#method.take_error" class="fn">take_error</a>(&amp;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;<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;, <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;</h4></section></summary><div class="docblock"><p>Returns the value of the <code>SO_ERROR</code> option.</p>
<h5 id="examples-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::net::UdpSocket;
<span class="kw">use </span>std::io;
<span class="attr">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="comment">// Create a socket
</span><span class="kw">let </span>socket = UdpSocket::bind(<span class="string">"0.0.0.0:8080"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">if let </span><span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(err)) = socket.take_error() {
<span class="macro">println!</span>(<span class="string">"Got error: {:?}"</span>, err);
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-AsFd-for-UdpSocket" class="impl"><a href="#impl-AsFd-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.as_fd" class="method trait-impl"><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="fn">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="toggle implementors-toggle" open><summary><section id="impl-AsRawFd-for-UdpSocket" class="impl"><a href="#impl-AsRawFd-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.as_raw_fd" class="method trait-impl"><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="fn">as_raw_fd</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</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="toggle implementors-toggle" open><summary><section id="impl-Debug-for-UdpSocket" class="impl"><a href="#impl-Debug-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><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="fn">fmt</a>(&amp;self, f: &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="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>&gt;</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="toggle implementors-toggle" open><summary><section id="imp
stream: <a class="struct" href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a>, &lt;<a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a>&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"><p>Consumes stream, returning the tokio I/O object.</p>
<p>This is equivalent to
<a href="struct.UdpSocket.html#method.from_std" title="associated function actix_rt::net::UdpSocket::from_std"><code>UdpSocket::from_std(stream)</code></a>.</p>
</div></details><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a href="#associatedtype.Error" 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="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-UdpSocket" class="impl"><a href="#impl-Freeze-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-RefUnwindSafe-for-UdpSocket" class="impl"><a href="#impl-RefUnwindSafe-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Send-for-UdpSocket" class="impl"><a href="#impl-Send-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Sync-for-UdpSocket" class="impl"><a href="#impl-Sync-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Unpin-for-UdpSocket" class="impl"><a href="#impl-Unpin-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-UnwindSafe-for-UdpSocket" class="impl"><a href="#impl-UnwindSafe-for-UdpSocket" 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.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#138">source</a><a href="#impl-Any-for-T" 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<div class="where">where
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#139">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="fn">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="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#209">source</a><a href="#impl-Borrow%3CT%3E-for-T" 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<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><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="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;T</a></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="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#217">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" 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<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#218">source</a><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="fn">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut T</a></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="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#765">source</a><a href="#impl-From%3CT%3E-for-T" 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="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#768">source</a><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="fn">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#748-750">source</a><a href="#impl-Into%3CU%3E-for-T" 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<div class="where">where
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;,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#758">source</a><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="fn">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="trait core::convert::From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#805-807">source</a><a href="#impl-TryFrom%3CU%3E-for-T" 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<div class="where">where
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;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-2" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#809">source</a><a href="#associatedtype.Error-2" 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="toggle method-toggle" open><summary><section id="method.try_from-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#812">source</a><a href="#method.try_from-1" 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="fn">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="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#790-792">source</a><a href="#impl-TryInto%3CU%3E-for-T" 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<div class="where">where
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;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#794">source</a><a href="#associatedtype.Error-1" 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="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#797">source</a><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="fn">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></body></html>