comparison src/error.rs @ 4:66c0e10c89fc

Support resolving hostnames Until now the crate supported only IP addresses and systemd sockets. This was troublesome because it prevented the popular `localhost:1234` format. This commit changes the behavior so that if parsing of `std::net::SocketAddr` fails it attempts to parse it as `hostname:port`. `bind_*()` methods were also modified to be async because of this.
author Martin Habovstiak <martin.habovstiak@gmail.com>
date Fri, 27 Nov 2020 15:05:19 +0100
parents cabc4aafdd85
children a7893294e9b2
comparison
equal deleted inserted replaced
3:0edcde404b02 4:66c0e10c89fc
16 pub struct ParseError(#[from] pub(crate) ParseErrorInner); 16 pub struct ParseError(#[from] pub(crate) ParseErrorInner);
17 17
18 #[derive(Debug, Error)] 18 #[derive(Debug, Error)]
19 pub(crate) enum ParseErrorInner { 19 pub(crate) enum ParseErrorInner {
20 #[error("failed to parse socket address")] 20 #[error("failed to parse socket address")]
21 SocketAddr(std::net::AddrParseError), 21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError),
22 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] 22 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")]
23 InvalidCharacter { string: String, c: char, pos: usize, }, 23 InvalidCharacter { string: String, c: char, pos: usize, },
24 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] 24 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")]
25 LongSocketName { string: String, len: usize, }, 25 LongSocketName { string: String, len: usize, },
26 } 26 }
56 56
57 #[derive(Debug, Error)] 57 #[derive(Debug, Error)]
58 pub(crate) enum BindErrorInner { 58 pub(crate) enum BindErrorInner {
59 #[error("failed to bind {addr}")] 59 #[error("failed to bind {addr}")]
60 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, 60 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, },
61 #[error("failed to bind {addr}")]
62 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, },
61 #[error("failed to receive descriptors with names")] 63 #[error("failed to receive descriptors with names")]
62 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), 64 ReceiveDescriptors(#[source] crate::systemd_sockets::Error),
63 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] 65 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")]
64 MissingDescriptor(String), 66 MissingDescriptor(String),
65 #[error("the systemd socket {0} is not an internet socket")] 67 #[error("the systemd socket {0} is not an internet socket")]