use ::std::net::TcpListener;
use ::std::thread;
use ::log::debug;
use ::log::error;
use crate::gen1::ErrMsg;
#[allow(unused)] fn accept_single_connection() -> Result<(), ErrMsg> {
let address = "127.0.0.1:47400";
let listener = TcpListener::bind(address).map_err(|err| {
format!(
"failed to listen for tcp connection on {}, err {}",
address, err
)
})?;
if let Some(connection) = listener.incoming().next() {
match connection {
Ok(_connection) => {}
Err(err) => panic!(
"failed to accept the first connection on {}, err {}",
address, err
),
}
}
thread::spawn(|| reject_extra_connections(listener));
Ok(())
}
#[allow(unused)] fn reject_extra_connections(listener: TcpListener) {
for extra_connection in listener.incoming() {
debug!("unexpected connection: {:?}", extra_connection);
error!("received more than one connection! this should not happen, it will be ignored");
}
}