aquatic_udp: glommio: fix access list update bug

This commit is contained in:
Joakim Frostegård 2021-10-27 20:37:32 +02:00
parent af5816e2ab
commit ead7650d41

View file

@ -1,3 +1,4 @@
use std::borrow::Borrow;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@ -8,18 +9,19 @@ use glommio::prelude::*;
use crate::common::*; use crate::common::*;
use crate::config::Config; use crate::config::Config;
pub async fn update_access_list(config: Config, access_list: Rc<RefCell<AccessList>>) { pub async fn update_access_list<C: Borrow<Config>>(config: C, access_list: Rc<RefCell<AccessList>>) {
if config.access_list.mode.is_on() { if config.borrow().access_list.mode.is_on() {
match BufferedFile::open(config.access_list.path).await { match BufferedFile::open(&config.borrow().access_list.path).await {
Ok(file) => { Ok(file) => {
let mut reader = StreamReaderBuilder::new(file).build(); let mut reader = StreamReaderBuilder::new(file).build();
let mut new_access_list = AccessList::default();
loop { loop {
let mut buf = String::with_capacity(42); let mut buf = String::with_capacity(42);
match reader.read_line(&mut buf).await { match reader.read_line(&mut buf).await {
Ok(_) => { Ok(_) => {
if let Err(err) = access_list.borrow_mut().insert_from_line(&buf) { if let Err(err) = new_access_list.insert_from_line(&buf) {
::log::error!( ::log::error!(
"Couln't parse access list line '{}': {:?}", "Couln't parse access list line '{}': {:?}",
buf, buf,
@ -36,6 +38,8 @@ pub async fn update_access_list(config: Config, access_list: Rc<RefCell<AccessLi
yield_if_needed().await; yield_if_needed().await;
} }
*access_list.borrow_mut() = new_access_list;
} }
Err(err) => { Err(err) => {
::log::error!("Couldn't open access list file: {:?}", err) ::log::error!("Couldn't open access list file: {:?}", err)