(config: ProxyConfig, app_state: Proxy)
| 239 | } |
| 240 | |
| 241 | pub fn start(config: ProxyConfig, app_state: Proxy) -> Result<()> { |
| 242 | std::thread::Builder::new() |
| 243 | .name("proxy-main".to_string()) |
| 244 | .spawn(move || { |
| 245 | // Create a new single-threaded runtime |
| 246 | let rt = tokio::runtime::Builder::new_current_thread() |
| 247 | .enable_all() |
| 248 | .build() |
| 249 | .or_panic("Failed to build Tokio runtime"); |
| 250 | |
| 251 | let worker_rt = tokio::runtime::Builder::new_multi_thread() |
| 252 | .thread_name("proxy-worker") |
| 253 | .enable_all() |
| 254 | .worker_threads(config.workers) |
| 255 | .build() |
| 256 | .or_panic("Failed to build Tokio runtime"); |
| 257 | |
| 258 | // Run the proxy_main function in this runtime |
| 259 | if let Err(err) = rt.block_on(proxy_main(&worker_rt, &config, app_state)) { |
| 260 | error!( |
| 261 | "error on {}:{:?}: {err:?}", |
| 262 | config.listen_addr, config.listen_port |
| 263 | ); |
| 264 | } |
| 265 | }) |
| 266 | .context("Failed to spawn proxy-main thread")?; |
| 267 | Ok(()) |
| 268 | } |
| 269 | |
| 270 | #[cfg(test)] |
| 271 | mod tests { |
no test coverage detected