mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
close sigchat websocket properly
This commit is contained in:
parent
89cdbc899e
commit
7346f03c1a
2 changed files with 30 additions and 11 deletions
|
|
@ -161,7 +161,7 @@ impl Manager {
|
|||
match SignalWS::new_provision(&host) {
|
||||
Ok(mut ws) => {
|
||||
log::info!("provisioning websocket established to {host}");
|
||||
match ws.read(Some(Duration::from_millis(5000))) {
|
||||
let result = match ws.read(Some(Duration::from_millis(5000))) {
|
||||
Ok(Message::Binary(uuid)) => {
|
||||
log::info!("received Provisioning UUID message from host");
|
||||
let uuid = libsignal::ProvisioningUuid::decode(uuid).id.clone();
|
||||
|
|
@ -185,7 +185,6 @@ impl Manager {
|
|||
match ws.read(Some(Duration::from_millis(5000))) {
|
||||
Ok(Message::Binary(registration)) => {
|
||||
log::info!("Registration message received from host");
|
||||
ws.close();
|
||||
match self.account.link(
|
||||
name,
|
||||
service_environment,
|
||||
|
|
@ -225,7 +224,9 @@ impl Manager {
|
|||
log::warn!("{e}");
|
||||
Err(link_err)
|
||||
}
|
||||
}
|
||||
};
|
||||
ws.close();
|
||||
result
|
||||
}
|
||||
Err(e) => {
|
||||
log::info!("failed to connect to server: {}", e);
|
||||
|
|
|
|||
|
|
@ -40,13 +40,30 @@ impl SignalWS {
|
|||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
if let Ok(mut ws) = self.ws.lock() {
|
||||
ws.close(None)
|
||||
.unwrap_or_else(|e| log::warn!("failed to close websocket: {e}"));
|
||||
// TODO close properly https://docs.rs/tungstenite/0.20.1/tungstenite/protocol/struct.WebSocket.html
|
||||
ws.flush()
|
||||
.unwrap_or_else(|e| log::warn!("failed to flush websocket: {e}"));
|
||||
};
|
||||
log::info!("attempting to close websocket connection");
|
||||
let ws = self.ws.clone();
|
||||
thread::spawn(move || loop {
|
||||
if let Ok(mut ws) = ws.lock() {
|
||||
ws.close(None)
|
||||
.unwrap_or_else(|e| log::warn!("failed to close websocket: {e}"));
|
||||
loop {
|
||||
match ws.flush() {
|
||||
Ok(()) => (),
|
||||
Err(
|
||||
tungstenite::Error::ConnectionClosed
|
||||
| tungstenite::Error::AlreadyClosed,
|
||||
) => {
|
||||
log::info!("websocket connection closed");
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("{e}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/// Reads a msg from the websocket with optional timeout
|
||||
|
|
@ -67,7 +84,8 @@ impl SignalWS {
|
|||
let ws = self.ws.clone();
|
||||
thread::spawn(move || {
|
||||
if let Ok(mut ws) = ws.lock() {
|
||||
tx.send(ws.read()).unwrap();
|
||||
tx.send(ws.read())
|
||||
.unwrap_or_else(|e| log::warn!("failed to forward ws msg: {e}"));
|
||||
}
|
||||
});
|
||||
match rx.recv_timeout(duration) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue