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"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hptp",
|
"hptp",
|
||||||
|
"thiserror",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -8,4 +8,6 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[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 hptp;
|
||||||
|
extern crate tokio;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate thiserror;
|
||||||
|
|
||||||
#[derive(Debug)]
|
use std::net::SocketAddrV4;
|
||||||
struct Hostname {
|
|
||||||
ip: String,
|
|
||||||
port: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct InvalidHostnameError;
|
#[derive(Error, Debug)]
|
||||||
|
enum Error {
|
||||||
impl FromStr for Hostname {
|
#[error("invalid command-line arguments")]
|
||||||
type Err = InvalidHostnameError;
|
InvalidArgs,
|
||||||
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(|_| ())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match parse_args() {
|
match entry() {
|
||||||
Ok(x) => start(x),
|
Err(Error::InvalidArgs) => print_usage(),
|
||||||
Err(_) => usage(),
|
/*
|
||||||
|
Err(e) => {
|
||||||
|
use std::error::Error;
|
||||||
|
println!("Error: {:?}", e);
|
||||||
|
for bt in e.backtrace() {
|
||||||
|
println!("{}", bt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
Ok(()) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(hn: Hostname) {
|
fn print_usage() {
|
||||||
println!("ip={}, port={}", hn.ip, hn.port)
|
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