aquatic_ws: use fn handle_handshake_result in one more location

This commit is contained in:
Joakim Frostegård 2020-05-11 14:29:27 +02:00
parent 583d323c7f
commit 656b0da3c6

View file

@ -307,42 +307,19 @@ pub fn read_and_forward_in_messages(
break; break;
} }
}, },
ConnectionStage::MidHandshake(mut handshake) => { ConnectionStage::MidHandshake(handshake) => {
let stream = handshake.get_mut().get_mut(); let stop_loop = handle_handshake_result(
let peer_socket_addr = stream.peer_addr().unwrap(); connections,
poll_token,
match handshake.handshake(){
Ok(ws) => {
println!("handshake established");
let peer_connection = PeerConnection {
ws,
peer_socket_addr,
valid_until, valid_until,
}; handshake.handshake()
);
let connection = Connection {
valid_until: Some(valid_until),
stage: ConnectionStage::Established(peer_connection)
};
connections.insert(poll_token, connection);
},
Err(HandshakeError::Interrupted(handshake)) => {
let connection = Connection {
valid_until: Some(valid_until),
stage: ConnectionStage::MidHandshake(handshake),
};
connections.insert(poll_token, connection);
if stop_loop {
break; break;
},
Err(HandshakeError::Failure(err)) => {
dbg!(err);
},
} }
}, },
_ => unreachable!(), ConnectionStage::Established(_) => unreachable!(),
} }
} else if let Some(Connection{ } else if let Some(Connection{
stage: ConnectionStage::Established(peer_connection), stage: ConnectionStage::Established(peer_connection),