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) { ...@@ -14,20 +14,21 @@ pub fn tcp_listener_handler<OME: OfpMsgEvent>(address: &str, ofp_version: u8) {
Ok(mut stream) => { Ok(mut stream) => {
let controller_clone = controller.clone(); let controller_clone = controller.clone();
thread::spawn(move || { thread::spawn(move || {
controller_clone let mut ctrl = match controller_clone.lock() {
.lock() Ok(guard) => guard,
.unwrap() Err(poinsoned) => {
.send_msg(HelloEvent::new(), 0, &mut stream); let guard = poinsoned.into_inner();
let ofp_size = controller_clone.lock().unwrap().get_ofp().header_size(); 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 ofp = controller.lock().unwrap().get_ofp();
let mut buffer = vec![0u8; ofp_size]; let mut buffer = vec![0u8; ofp_size];
loop { loop {
match stream.read(&mut buffer) { match stream.read(&mut buffer) {
Ok(v) if v > 0 => { Ok(v) if v > 0 => {
controller_clone ctrl.request_handler(&mut buffer, &mut stream);
.lock()
.unwrap()
.request_handler(&mut buffer, &mut stream);
} }
Ok(_) | Err(_) => break, 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