-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5950 from habitat-sh/peck/listen-ctl
ListenCtlAddr type
- Loading branch information
Showing
20 changed files
with
292 additions
and
130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2018 Chef Software Inc. and/or applicable contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::fmt; | ||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; | ||
use std::result; | ||
use std::str::FromStr; | ||
|
||
use super::env_config::EnvConfig; | ||
use error::{Error, Result}; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct ListenCtlAddr(SocketAddr); | ||
|
||
impl ListenCtlAddr { | ||
pub const DEFAULT_PORT: u16 = 9632; | ||
|
||
pub fn new(ip: Ipv4Addr, port: u16) -> Self { | ||
ListenCtlAddr(SocketAddr::V4(SocketAddrV4::new(ip, port))) | ||
} | ||
|
||
pub fn ip(&self) -> IpAddr { | ||
self.0.ip() | ||
} | ||
|
||
pub fn port(&self) -> u16 { | ||
self.0.port() | ||
} | ||
} | ||
|
||
impl Default for ListenCtlAddr { | ||
fn default() -> ListenCtlAddr { | ||
ListenCtlAddr::new(Ipv4Addr::LOCALHOST, ListenCtlAddr::DEFAULT_PORT) | ||
} | ||
} | ||
|
||
impl EnvConfig for ListenCtlAddr { | ||
const ENVVAR: &'static str = "HAB_LISTEN_CTL"; | ||
} | ||
|
||
impl FromStr for ListenCtlAddr { | ||
type Err = Error; | ||
|
||
fn from_str(val: &str) -> Result<Self> { | ||
Ok(val.parse::<SocketAddr>()?.into()) | ||
} | ||
} | ||
|
||
impl fmt::Display for ListenCtlAddr { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl From<SocketAddr> for ListenCtlAddr { | ||
fn from(socket_addr: SocketAddr) -> Self { | ||
ListenCtlAddr(socket_addr) | ||
} | ||
} | ||
|
||
impl AsRef<SocketAddr> for ListenCtlAddr { | ||
fn as_ref(&self) -> &SocketAddr { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.