Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greister/3a95d24796df9e9e1e229128c4c2fc21 to your computer and use it in GitHub Desktop.
Save greister/3a95d24796df9e9e1e229128c4c2fc21 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
// incoming packet handler and reconnection thread
thread::spawn(move || {
// get underlying tcpstream clone from connection object
let mut _stream_pkt_hndlr_thrd = {
let ref connection = *_client_pkt_hndlr_thrd.connection.lock().unwrap();
let stream = match connection.stream {
Some(ref s) => s,
None => panic!("No stream found in the connectino"),
};
stream.try_clone().unwrap()
};
loop {
// blocking
let packet = match VariablePacket::decode(&mut _stream_pkt_hndlr_thrd) {
Ok(pk) => pk,
Err(err) => {
println!("error in receiving packet {:?}", err);
let mut connection = _client_pkt_hndlr_thrd.connection.lock().unwrap();
if connection.retry(3) {
continue;
} else {
// do an on weird callback here so that user can handle disconnection
unimplemented!();
continue; //remove this later
}
}
};
_client_pkt_hndlr_thrd.handle_packet(&packet);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment