diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-09 20:15:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-09 20:15:54 +0200 |
commit | 8147d03b44323172454601523a18060edbb0ab9f (patch) | |
tree | bc3bd3884c429460156deae050e04491d8e79460 /server/src | |
parent | a748325cd48adcd7a4cf4775cc3812e1a2dbe630 (diff) | |
download | keks-meet-8147d03b44323172454601523a18060edbb0ab9f.tar keks-meet-8147d03b44323172454601523a18060edbb0ab9f.tar.bz2 keks-meet-8147d03b44323172454601523a18060edbb0ab9f.tar.zst |
clean code
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/main.rs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 9f5cb91..ddc00af 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -102,24 +102,12 @@ async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> { fn signaling_connect(rname: String, rooms: Rooms, ws: warp::ws::Ws) -> impl Reply { async fn inner(sock: WebSocket, rname: String, rooms: Rooms) { debug!("ws upgrade"); - let guard = rooms.read().await; - let room = match guard.get(&rname) { - Some(r) => { - let x = r.to_owned(); - drop(guard); - x - } - None => { - debug!("aquire lock for insertion"); - drop(guard); // make sure read-lock is dropped to avoid deadlock - let mut guard = rooms.write().await; - debug!("create new room"); - guard.insert(rname.to_owned(), Default::default()); - let x = guard.get(&rname).unwrap().to_owned(); - drop(guard); - x - } - }; + let mut guard = rooms.write().await; + let room = guard + .entry(rname.clone()) + .or_insert_with(|| Default::default()) + .to_owned(); + drop(guard); room.client_connect(sock).await; if room.should_remove().await { |