Mercurial > crates > systemd-socket
diff 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 |
line wrap: on
line diff
--- a/src/error.rs Fri Nov 27 12:56:37 2020 +0100 +++ b/src/error.rs Fri Nov 27 15:05:19 2020 +0100 @@ -18,7 +18,7 @@ #[derive(Debug, Error)] pub(crate) enum ParseErrorInner { #[error("failed to parse socket address")] - SocketAddr(std::net::AddrParseError), + ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] InvalidCharacter { string: String, c: char, pos: usize, }, #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] @@ -58,6 +58,8 @@ pub(crate) enum BindErrorInner { #[error("failed to bind {addr}")] BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, + #[error("failed to bind {addr}")] + BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, #[error("failed to receive descriptors with names")] ReceiveDescriptors(#[source] crate::systemd_sockets::Error), #[error("missing systemd socket {0} - a typo or an attempt to bind twice")]