mirror of https://github.com/vinc/moros.git
Improve http timeout (#397)
This commit is contained in:
parent
0724b5a07b
commit
5d0451e379
|
@ -14,6 +14,7 @@ This project started from the [seventh post][1] of the second edition of
|
||||||
[![Travis](https://img.shields.io/travis/vinc/moros/master.svg)](https://travis-ci.org/vinc/moros/branches)
|
[![Travis](https://img.shields.io/travis/vinc/moros/master.svg)](https://travis-ci.org/vinc/moros/branches)
|
||||||
[![Crates.io](https://img.shields.io/crates/v/moros.svg)](https://crates.io/crates/moros)
|
[![Crates.io](https://img.shields.io/crates/v/moros.svg)](https://crates.io/crates/moros)
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] External bootloader (using [bootloader](https://github.com/rust-osdev/bootloader))
|
- [x] External bootloader (using [bootloader](https://github.com/rust-osdev/bootloader))
|
||||||
|
@ -96,7 +97,7 @@ Run the test suite in QEMU:
|
||||||
$ make test
|
$ make test
|
||||||
|
|
||||||
|
|
||||||
## LICENSE
|
## License
|
||||||
|
|
||||||
MOROS is released under MIT.
|
MOROS is released under MIT.
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,10 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||||
let mut is_verbose = false;
|
let mut is_verbose = false;
|
||||||
let mut host = "";
|
let mut host = "";
|
||||||
let mut path = "";
|
let mut path = "";
|
||||||
|
let mut timeout = 5.0;
|
||||||
|
let mut i = 1;
|
||||||
let n = args.len();
|
let n = args.len();
|
||||||
for i in 1..n {
|
while i < n {
|
||||||
match args[i] {
|
match args[i] {
|
||||||
"-h" | "--help" => {
|
"-h" | "--help" => {
|
||||||
return help();
|
return help();
|
||||||
|
@ -61,6 +63,15 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||||
"-v" | "--verbose" => {
|
"-v" | "--verbose" => {
|
||||||
is_verbose = true;
|
is_verbose = true;
|
||||||
}
|
}
|
||||||
|
"-t" | "--timeout" => {
|
||||||
|
if i + 1 < n {
|
||||||
|
timeout = args[i + 1].parse().unwrap_or(timeout);
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
error!("Missing timeout seconds");
|
||||||
|
return Err(ExitCode::UsageError);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if args[i].starts_with("-") {
|
if args[i].starts_with("-") {
|
||||||
error!("Invalid option '{}'", args[i]);
|
error!("Invalid option '{}'", args[i]);
|
||||||
|
@ -75,6 +86,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if host.is_empty() && path.is_empty() {
|
if host.is_empty() && path.is_empty() {
|
||||||
|
@ -113,11 +125,10 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||||
|
|
||||||
if let Some(ref mut iface) = *sys::net::IFACE.lock() {
|
if let Some(ref mut iface) = *sys::net::IFACE.lock() {
|
||||||
let tcp_handle = iface.add_socket(tcp_socket);
|
let tcp_handle = iface.add_socket(tcp_socket);
|
||||||
let timeout = 5.0;
|
let mut last_received_at = clock::realtime();
|
||||||
let started = clock::realtime();
|
|
||||||
let mut response_state = ResponseState::Headers;
|
let mut response_state = ResponseState::Headers;
|
||||||
loop {
|
loop {
|
||||||
if clock::realtime() - started > timeout {
|
if clock::realtime() - last_received_at > timeout {
|
||||||
error!("Timeout reached");
|
error!("Timeout reached");
|
||||||
iface.remove_socket(tcp_handle);
|
iface.remove_socket(tcp_handle);
|
||||||
return Err(ExitCode::Failure);
|
return Err(ExitCode::Failure);
|
||||||
|
@ -172,6 +183,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
|
||||||
}
|
}
|
||||||
SessionState::Response if socket.can_recv() => {
|
SessionState::Response if socket.can_recv() => {
|
||||||
socket.recv(|data| {
|
socket.recv(|data| {
|
||||||
|
last_received_at = clock::realtime();
|
||||||
let n = data.len();
|
let n = data.len();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < n {
|
while i < n {
|
||||||
|
@ -233,6 +245,7 @@ fn help() -> Result<(), ExitCode> {
|
||||||
println!("{}Usage:{} http {}<options> <url>{1}", csi_title, csi_reset, csi_option);
|
println!("{}Usage:{} http {}<options> <url>{1}", csi_title, csi_reset, csi_option);
|
||||||
println!();
|
println!();
|
||||||
println!("{}Options:{}", csi_title, csi_reset);
|
println!("{}Options:{}", csi_title, csi_reset);
|
||||||
println!(" {0}-v{1}, {0}--verbose{1} Increase verbosity", csi_option, csi_reset);
|
println!(" {0}-v{1}, {0}--verbose{1} Increase verbosity", csi_option, csi_reset);
|
||||||
|
println!(" {0}-t{1}, {0}--timeout <seconds>{1} Request timeout", csi_option, csi_reset);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue