1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![allow(missing_docs)] // TODO: add docs

use crate::{
    net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs, UdpSocket},
    sys,
};
use std::{io, time::Duration};

// FIXME: lots more to do here

pub struct Catalog {
    sys: sys::net::Catalog,
}

impl Catalog {
    #[inline]
    pub fn bind_tcp_listener<A: ToSocketAddrs>(&self, addr: A) -> io::Result<TcpListener> {
        self.sys.bind_tcp_listener(addr.to_socket_addrs()?)
    }

    #[inline]
    pub fn connect_tcp_stream<A: ToSocketAddrs>(&self, addr: A) -> io::Result<TcpStream> {
        self.sys.connect_tcp_stream(addr.to_socket_addrs()?)
    }

    #[inline]
    pub fn connect_timeout_tcp_stream(
        &self,
        addr: &SocketAddr,
        timeout: Duration,
    ) -> io::Result<TcpStream> {
        self.sys.connect_timeout_tcp_stream(addr, timeout)
    }

    #[inline]
    pub fn bind_udp_socket<A: ToSocketAddrs>(&self, addr: A) -> io::Result<UdpSocket> {
        self.sys.bind_udp_socket(addr.to_socket_addrs()?)
    }

    #[inline]
    pub fn send_to_udp_socket_addr<A: ToSocketAddrs>(
        &self,
        udp_socket: &UdpSocket,
        buf: &[u8],
        addr: A,
    ) -> io::Result<usize> {
        self.sys
            .send_to_udp_socket_addr(udp_socket, buf, addr.to_socket_addrs()?)
    }

    #[inline]
    pub fn connect_udp_socket<A: ToSocketAddrs>(
        &self,
        udp_socket: &UdpSocket,
        addr: A,
    ) -> io::Result<()> {
        self.sys
            .connect_udp_socket(udp_socket, addr.to_socket_addrs()?)
    }
}