Commit ade22534 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

fix #2 handle error instead of unwrap

parent 98f795c2
......@@ -14,20 +14,21 @@ pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str, ofp_version: u8) {
Ok(mut stream) => {
let controller_clone = controller.clone();
thread::spawn(move || {
controller_clone
.lock()
.unwrap()
.send_msg(HelloEvent::new(), 0, &mut stream);
let ofp_size = controller_clone.lock().unwrap().get_ofp().header_size();
let mut ctrl = match controller_clone.lock() {
Ok(guard) => guard,
Err(poinsoned) => {
let guard = poinsoned.into_inner();
guard
}
};
ctrl.send_msg(HelloEvent::new(), 0, &mut stream);
let ofp_size = ctrl.get_ofp().header_size();
// let ofp = controller.lock().unwrap().get_ofp();
let mut buffer = vec![0u8; ofp_size];
loop {
match stream.read(&mut buffer) {
Ok(v) if v > 0 => {
controller_clone
.lock()
.unwrap()
.request_handler(&mut buffer, &mut stream);
ctrl.request_handler(&mut buffer, &mut stream);
}
Ok(_) | Err(_) => break,
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment