This commit is contained in:
Pierre HUBERT 2022-08-30 14:23:00 +02:00
parent 1eedfba81c
commit dff4384bd8
2 changed files with 15 additions and 5 deletions

View File

@ -41,16 +41,16 @@ async fn relay_connection(ws_url: String, socket: TcpStream) {
loop {
match tcp_read.read(&mut buff).await {
Ok(s) => {
if s == 0 {
log::info!("Got empty read TCP buffer. Stopping...");
break;
}
if let Err(e) = ws_write.send(Message::Binary(Vec::from(&buff[0..s]))).await {
log::error!(
"Failed to write to WS connection! {:?} Exiting TCP read -> WS write loop...",e);
break;
}
if s == 0 {
log::info!("Got empty read TCP buffer. Stopping...");
break;
}
}
Err(e) => {
log::error!(

View File

@ -36,6 +36,11 @@ impl Actor for RelayWS {
loop {
match read_half.read(&mut buff).await {
Ok(l) => {
if l == 0 {
log::info!("Got empty read. Closing read end...");
return;
}
let to_send = DataForWebSocket(Vec::from(&buff[0..l]));
if let Err(e) = addr.send(to_send).await {
log::error!("Failed to send to websocket. Stopping now... {:?}", e);
@ -69,6 +74,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for RelayWS {
log::error!("Failed to forward some data, closing connection! {:?}", e);
ctx.stop();
}
if data.is_empty() {
log::info!("Got empty binary message. Closing websocket...");
ctx.stop();
}
}
_ => (),
}