| 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | // file at the top-level directory of this distribution and at |
| 3 | // http://rust-lang.org/COPYRIGHT. |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | // option. This file may not be copied, modified, or distributed |
| 9 | // except according to those terms. |
| 10 | |
| 11 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 13 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::{ToSocketAddrsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/socket_addr/ToSocketAddrs#, UdpSocketrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/udp/UdpSocket#}; |
| 15 | |
| 16 | use IntoInnerrust-analyzer cargo net2 0.2.39 IntoInner#; |
| 17 | use socket::Socket; |
| 18 | use sys::c; |
| 19 | |
| 20 | /// An "in progress" UDP socket which has not yet been connected. |
| 21 | /// |
| 22 | /// Allows configuration of a socket before the socket is connected. |
| 23 | pub struct UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 24 | socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Socketrust-analyzer cargo net2 0.2.39 socket/Socket#>>, |
| 25 | } |
| 26 | |
| 27 | impl UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 28 | /// Constructs a new UdpBuilder with the `AF_INET` domain, the `SOCK_DGRAM` |
| 29 | /// type, and with a protocol argument of 0. |
| 30 | /// |
| 31 | /// Note that passing other kinds of flags or arguments can be done through |
| 32 | /// the `FromRaw{Fd,Socket}` implementation. |
| 33 | pub fn new_v4rust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder]new_v4().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#> { |
| 34 | Socketrust-analyzer cargo net2 0.2.39 socket/Socket#::newrust-analyzer cargo net2 0.2.39 socket/impl#[Socket]new().(crust-analyzer cargo net2 0.2.39 sys/c/::AF_INETrust-analyzer cargo libc 0.2.189 unix/linux_like/AF_INET., crust-analyzer cargo net2 0.2.39 sys/c/::SOCK_DGRAMrust-analyzer cargo libc 0.2.189 unix/linux_like/linux/gnu/b64/x86_64/SOCK_DGRAM.).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(::FromInnerrust-analyzer cargo net2 0.2.39 FromInner#::from_innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][FromInner]from_inner().) |
| 35 | } |
| 36 | |
| 37 | /// Constructs a new UdpBuilder with the `AF_INET6` domain, the `SOCK_DGRAM` |
| 38 | /// type, and with a protocol argument of 0. |
| 39 | /// |
| 40 | /// Note that passing other kinds of flags or arguments can be done through |
| 41 | /// the `FromRaw{Fd,Socket}` implementation. |
| 42 | pub fn new_v6rust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder]new_v6().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#> { |
| 43 | Socketrust-analyzer cargo net2 0.2.39 socket/Socket#::newrust-analyzer cargo net2 0.2.39 socket/impl#[Socket]new().(crust-analyzer cargo net2 0.2.39 sys/c/::AF_INET6rust-analyzer cargo libc 0.2.189 unix/linux_like/AF_INET6., crust-analyzer cargo net2 0.2.39 sys/c/::SOCK_DGRAMrust-analyzer cargo libc 0.2.189 unix/linux_like/linux/gnu/b64/x86_64/SOCK_DGRAM.).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(::FromInnerrust-analyzer cargo net2 0.2.39 FromInner#::from_innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][FromInner]from_inner().) |
| 44 | } |
| 45 | |
| 46 | /// Binds this socket to the specified address. |
| 47 | /// |
| 48 | /// This function directly corresponds to the bind(2) function on Windows |
| 49 | /// and Unix. |
| 50 | pub fn bindrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder]bind().<T>(&self, addr: T) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<UdpSocketrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/udp/UdpSocket#> |
| 51 | where T: ToSocketAddrsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/socket_addr/ToSocketAddrs# |
| 52 | { |
| 53 | tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(self.with_socketrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder]with_socket().(|sock| { |
| 54 | let addr = tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/`r#try`!!(::one_addrrust-analyzer cargo net2 0.2.39 one_addr().(addr)); |
| 55 | sock.bindrust-analyzer cargo net2 0.2.39 socket/impl#[Socket]bind().(&addr) |
| 56 | })); |
| 57 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().into_innerrust-analyzer cargo net2 0.2.39 socket/impl#[Socket][IntoInner]into_inner().().into_udp_socketrust-analyzer cargo net2 0.2.39 sys/impl#[Socket]into_udp_socket().()) |
| 58 | } |
| 59 | |
| 60 | fn with_socketrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder]with_socket().<F>(&self, f: F) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 61 | where F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&Socketrust-analyzer cargo net2 0.2.39 socket/Socket#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 62 | { |
| 63 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Ref<'_, T>`][Deref]deref().self.socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().() { |
| 64 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref s) => f(s), |
| 65 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, |
| 66 | "builder has already finished its socket")), |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 72 | fn fmtrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 73 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "UdpBuilder {{ socket: {:?} }}", |
| 74 | self.socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl ::AsInnerrust-analyzer cargo net2 0.2.39 AsInner# for UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 79 | type Innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][AsInner]Inner# = RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Socketrust-analyzer cargo net2 0.2.39 socket/Socket#>>; |
| 80 | fn as_innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][AsInner]as_inner().(&self) -> &RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Socketrust-analyzer cargo net2 0.2.39 socket/Socket#>> { &self.socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket. } |
| 81 | } |
| 82 | |
| 83 | impl ::FromInnerrust-analyzer cargo net2 0.2.39 FromInner# for UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 84 | type Innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][FromInner]Inner# = Socketrust-analyzer cargo net2 0.2.39 socket/Socket#; |
| 85 | fn from_innerrust-analyzer cargo net2 0.2.39 udp/impl#[UdpBuilder][FromInner]from_inner().(sock: Socketrust-analyzer cargo net2 0.2.39 socket/Socket#) -> UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { |
| 86 | UdpBuilderrust-analyzer cargo net2 0.2.39 udp/UdpBuilder# { socketrust-analyzer cargo net2 0.2.39 udp/UdpBuilder#socket.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(sock)) } |
| 87 | } |
| 88 | } |
| 89 |