Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions turn/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ impl Server {
pub async fn delete_allocations_by_username(&self, username: String) -> Result<()> {
let tx = {
let command_tx = self.command_tx.lock().await;
command_tx.clone()
command_tx.clone().ok_or(Error::ErrClosed)?
};
if let Some(tx) = tx {
let (closed_tx, closed_rx) = mpsc::channel(1);
tx.send(Command::DeleteAllocations(username, Arc::new(closed_rx)))
.map_err(|_| Error::ErrClosed)?;

closed_tx.closed().await;
let (closed_tx, closed_rx) = mpsc::channel(1);
tx.send(Command::DeleteAllocations(username, Arc::new(closed_rx)))
.map_err(|_| Error::ErrClosed)?;

Ok(())
} else {
Err(Error::ErrClosed)
}
closed_tx.closed().await;

Ok(())
}

/// Get information of [`Allocation`][`Allocation`]s by specified [`FiveTuple`]s.
Expand All @@ -121,23 +118,20 @@ impl Server {

let tx = {
let command_tx = self.command_tx.lock().await;
command_tx.clone()
command_tx.clone().ok_or(Error::ErrClosed)?
};
if let Some(tx) = tx {
let (infos_tx, mut infos_rx) = mpsc::channel(1);
tx.send(Command::GetAllocationsInfo(five_tuples, infos_tx))
.map_err(|_| Error::ErrClosed)?;

let mut info: HashMap<FiveTuple, AllocationInfo> = HashMap::new();
let (infos_tx, mut infos_rx) = mpsc::channel(1);
tx.send(Command::GetAllocationsInfo(five_tuples, infos_tx))
.map_err(|_| Error::ErrClosed)?;

for _ in 0..tx.receiver_count() {
info.extend(infos_rx.recv().await.ok_or(Error::ErrClosed)?);
}
let mut info: HashMap<FiveTuple, AllocationInfo> = HashMap::new();

Ok(info)
} else {
Err(Error::ErrClosed)
for _ in 0..tx.receiver_count() {
info.extend(infos_rx.recv().await.ok_or(Error::ErrClosed)?);
}

Ok(info)
}

async fn read_loop(
Expand Down
Loading