1
2
3
4
5
6
7
8
9
10
11
12
13
use std::io::Write;
use std::net::TcpStream;
use crate::constants::KEEPALIVE_MESSAGE;

/// # Panics
///
/// - Will panic when stream is no longer open/wirteable
pub fn keep_alive(mut stream: TcpStream, duration: u16) {
    loop {
        crate::utilities::sleep(u64::from(duration));
        stream.write_all(KEEPALIVE_MESSAGE.as_bytes()).unwrap();
    }
}