(
cache_size: usize,
cache_path: PathBuf,
durable_fs: bool,
addr: net::SocketAddr,
mut shutdown_rx: oneshot::Receiver<()>,
)
| 182 | } |
| 183 | |
| 184 | async fn run_server( |
| 185 | cache_size: usize, |
| 186 | cache_path: PathBuf, |
| 187 | durable_fs: bool, |
| 188 | addr: net::SocketAddr, |
| 189 | mut shutdown_rx: oneshot::Receiver<()>, |
| 190 | ) { |
| 191 | info!(%cache_size, ?cache_path, %addr, "Starting with parameters."); |
| 192 | |
| 193 | // Setup the cache here. |
| 194 | let cache = match ArcDiskCache::new(cache_size, &cache_path, durable_fs) { |
| 195 | Ok(l) => Arc::new(l), |
| 196 | Err(err) => { |
| 197 | error!(?err, "Could not create Arc Disk Cache"); |
| 198 | return; |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | let listener = match TcpListener::bind(&addr).await { |
| 203 | Ok(l) => l, |
| 204 | Err(e) => { |
| 205 | error!("Could not bind to redis server address {} -> {:?}", addr, e); |
| 206 | return; |
| 207 | } |
| 208 | }; |
| 209 | |
| 210 | let (tx, _rx) = broadcast::channel(1); |
| 211 | |
| 212 | trace!("Listening on {:?}", addr); |
| 213 | |
| 214 | loop { |
| 215 | tokio::select! { |
| 216 | Ok(()) = &mut shutdown_rx => { |
| 217 | tx.send(()) |
| 218 | .expect("Unable to broadcast shutdown!"); |
| 219 | break; |
| 220 | } |
| 221 | res = listener.accept() => { |
| 222 | match res { |
| 223 | Ok((tcpstream, client_socket_addr)) => { |
| 224 | tcpstream.set_nodelay(true).expect("Unable to set no delay"); |
| 225 | // Start the event |
| 226 | let (r, w) = tokio::io::split(tcpstream); |
| 227 | let r = FramedRead::new(r, RedisCodec::new(cache.clone())); |
| 228 | let w = FramedWrite::new(w, RedisCodec::new(cache.clone())); |
| 229 | let c_rx = tx.subscribe(); |
| 230 | let c_cache = cache.clone(); |
| 231 | // Let it rip. |
| 232 | tokio::spawn(client_process(r, w, client_socket_addr, c_rx, c_cache)); |
| 233 | } |
| 234 | Err(e) => { |
| 235 | error!("TCP acceptor error, continuing -> {:?}", e); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 |
no outgoing calls
no test coverage detected