mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
aquatic_ws: streamline network code
This commit is contained in:
parent
68abecdaa5
commit
021fd554b0
1 changed files with 18 additions and 36 deletions
|
|
@ -198,8 +198,6 @@ pub fn handle_ws_handshake_result(
|
||||||
};
|
};
|
||||||
|
|
||||||
connections.insert(poll_token, connection);
|
connections.insert(poll_token, connection);
|
||||||
|
|
||||||
false
|
|
||||||
},
|
},
|
||||||
Err(HandshakeError::Interrupted(handshake)) => {
|
Err(HandshakeError::Interrupted(handshake)) => {
|
||||||
println!("interrupted");
|
println!("interrupted");
|
||||||
|
|
@ -211,14 +209,14 @@ pub fn handle_ws_handshake_result(
|
||||||
|
|
||||||
connections.insert(poll_token, connection);
|
connections.insert(poll_token, connection);
|
||||||
|
|
||||||
true
|
return true
|
||||||
},
|
},
|
||||||
Err(HandshakeError::Failure(err)) => {
|
Err(HandshakeError::Failure(err)) => {
|
||||||
dbg!(err);
|
dbg!(err);
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -266,35 +264,27 @@ pub fn run_handshakes_and_read_messages(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(connection) = connections.remove(&poll_token) {
|
} else if let Some(connection) = connections.remove(&poll_token) {
|
||||||
match connection.stage {
|
let stop_loop = match connection.stage {
|
||||||
ConnectionStage::TcpStream(stream) => {
|
ConnectionStage::TcpStream(stream) => {
|
||||||
if let Some(tls_acceptor) = opt_tls_acceptor {
|
if let Some(tls_acceptor) = opt_tls_acceptor {
|
||||||
let stop_loop = handle_tls_handshake_result(
|
handle_tls_handshake_result(
|
||||||
connections,
|
connections,
|
||||||
poll_token,
|
poll_token,
|
||||||
valid_until,
|
valid_until,
|
||||||
tls_acceptor.accept(stream)
|
tls_acceptor.accept(stream)
|
||||||
);
|
)
|
||||||
|
|
||||||
if stop_loop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let handshake_result = ::tungstenite::server::accept_hdr(
|
let handshake_result = ::tungstenite::server::accept_hdr(
|
||||||
Stream::TcpStream(stream),
|
Stream::TcpStream(stream),
|
||||||
DebugCallback
|
DebugCallback
|
||||||
);
|
);
|
||||||
|
|
||||||
let stop_loop = handle_ws_handshake_result(
|
handle_ws_handshake_result(
|
||||||
connections,
|
connections,
|
||||||
poll_token,
|
poll_token,
|
||||||
valid_until,
|
valid_until,
|
||||||
handshake_result
|
handshake_result
|
||||||
);
|
)
|
||||||
|
|
||||||
if stop_loop {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ConnectionStage::TlsStream(stream) => {
|
ConnectionStage::TlsStream(stream) => {
|
||||||
|
|
@ -303,42 +293,34 @@ pub fn run_handshakes_and_read_messages(
|
||||||
DebugCallback
|
DebugCallback
|
||||||
);
|
);
|
||||||
|
|
||||||
let stop_loop = handle_ws_handshake_result(
|
handle_ws_handshake_result(
|
||||||
connections,
|
connections,
|
||||||
poll_token,
|
poll_token,
|
||||||
valid_until,
|
valid_until,
|
||||||
handshake_result
|
handshake_result
|
||||||
);
|
)
|
||||||
|
|
||||||
if stop_loop {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ConnectionStage::TlsMidHandshake(handshake) => {
|
ConnectionStage::TlsMidHandshake(handshake) => {
|
||||||
let stop_loop = handle_tls_handshake_result(
|
handle_tls_handshake_result(
|
||||||
connections,
|
connections,
|
||||||
poll_token,
|
poll_token,
|
||||||
valid_until,
|
valid_until,
|
||||||
handshake.handshake()
|
handshake.handshake()
|
||||||
);
|
)
|
||||||
|
|
||||||
if stop_loop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ConnectionStage::WsMidHandshake(handshake) => {
|
ConnectionStage::WsMidHandshake(handshake) => {
|
||||||
let stop_loop = handle_ws_handshake_result(
|
handle_ws_handshake_result(
|
||||||
connections,
|
connections,
|
||||||
poll_token,
|
poll_token,
|
||||||
valid_until,
|
valid_until,
|
||||||
handshake.handshake()
|
handshake.handshake()
|
||||||
);
|
)
|
||||||
|
|
||||||
if stop_loop {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ConnectionStage::EstablishedWs(_) => unreachable!(),
|
ConnectionStage::EstablishedWs(_) => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if stop_loop {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue