Add a keep-alive and timeout demo to the examples.

v0.7.x
whitequark 2017-09-24 13:58:53 +00:00
parent cfcbcea4eb
commit 42b3a71f72
2 changed files with 5 additions and 2 deletions

View File

@ -206,7 +206,8 @@ It responds to:
* TCP connections on port 6970 (`socat stdio tcp4-connect:192.168.69.1:6970 <<<"abcdefg"`),
where it will respond with reversed chunks of the input indefinitely.
* TCP connections on port 6971 (`socat stdio tcp4-connect:192.168.69.1:6971 </dev/urandom`),
which will sink data.
which will sink data. Also, keep-alive packets (every 1 s) and a user timeout (at 2 s)
are enabled on this port; try to trigger them using fault injection.
* TCP connections on port 6972 (`socat stdio tcp4-connect:192.168.69.1:6972 >/dev/null`),
which will source data.

View File

@ -147,7 +147,9 @@ fn main() {
{
let socket: &mut TcpSocket = sockets.get_mut(tcp3_handle).as_socket();
if !socket.is_open() {
socket.listen(6971).unwrap()
socket.listen(6971).unwrap();
socket.set_keep_alive(Some(1000));
socket.set_timeout(Some(2000));
}
if socket.may_recv() {