hptp-send is becoming more webscale
This commit is contained in:
parent
28c779c843
commit
9acf848116
|
@ -55,6 +55,8 @@ name = "hptp-send"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hptp",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -8,4 +8,6 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
hptp = { path = "../hptp" }
|
||||
hptp = { path = "../hptp" }
|
||||
tokio = { version = "0.2.*", features = ["rt-core", "udp"] }
|
||||
thiserror = "*"
|
|
@ -1,41 +1,53 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
// #![feature(backtrace)]
|
||||
extern crate hptp;
|
||||
extern crate tokio;
|
||||
#[macro_use]
|
||||
extern crate thiserror;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Hostname {
|
||||
ip: String,
|
||||
port: u16,
|
||||
}
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
struct InvalidHostnameError;
|
||||
|
||||
impl FromStr for Hostname {
|
||||
type Err = InvalidHostnameError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let i = s.find(':').ok_or(InvalidHostnameError)?;
|
||||
Ok(Hostname {
|
||||
ip: s[..i].into(),
|
||||
port: s[i + 1..].parse().map_err(|_| InvalidHostnameError)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn usage() {
|
||||
print!("usage:\n./3700send <host-ip>:<host-port>\n")
|
||||
}
|
||||
|
||||
fn parse_args() -> Result<Hostname, ()> {
|
||||
std::env::args().nth(1).ok_or(())?.parse().map_err(|_| ())
|
||||
#[derive(Error, Debug)]
|
||||
enum Error {
|
||||
#[error("invalid command-line arguments")]
|
||||
InvalidArgs,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match parse_args() {
|
||||
Ok(x) => start(x),
|
||||
Err(_) => usage(),
|
||||
match entry() {
|
||||
Err(Error::InvalidArgs) => print_usage(),
|
||||
/*
|
||||
Err(e) => {
|
||||
use std::error::Error;
|
||||
println!("Error: {:?}", e);
|
||||
for bt in e.backtrace() {
|
||||
println!("{}", bt);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Ok(()) => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn start(hn: Hostname) {
|
||||
println!("ip={}, port={}", hn.ip, hn.port)
|
||||
fn print_usage() {
|
||||
print!("usage:\n./3700send <host-ip>:<host-port>\n")
|
||||
}
|
||||
|
||||
fn entry() -> Result<(), Error> {
|
||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||
// let mut log = Logger::new();
|
||||
rt.block_on(start())
|
||||
}
|
||||
|
||||
async fn start() -> Result<(), Error> {
|
||||
let addr = parse_arg()?;
|
||||
println!("ip={}, port={}", addr.ip(), addr.port());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_arg() -> Result<SocketAddrV4, Error> {
|
||||
std::env::args()
|
||||
.nth(1)
|
||||
.ok_or(Error::InvalidArgs)?
|
||||
.parse()
|
||||
.map_err(|_| Error::InvalidArgs)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue