From 66216657ec3f5d4f5ee0616fd3b9cb7afb99ef00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 23 May 2020 20:24:49 +0200 Subject: [PATCH] aquatic_ws: name worker threads Note: simplelog doesn't seem to pick up thread names, but this commit is good anyway, since they can be displayed in e.g. htop on Linux --- aquatic_ws/src/lib/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aquatic_ws/src/lib/lib.rs b/aquatic_ws/src/lib/lib.rs index 356c970..f656f1b 100644 --- a/aquatic_ws/src/lib/lib.rs +++ b/aquatic_ws/src/lib/lib.rs @@ -2,6 +2,7 @@ use std::time::Duration; use std::fs::File; use std::io::Read; use std::sync::Arc; +use std::thread::Builder; use anyhow::Context; use native_tls::{Identity, TlsAcceptor}; @@ -48,7 +49,7 @@ pub fn run(config: Config) -> anyhow::Result<()> { out_message_senders.push(out_message_sender); - ::std::thread::spawn(move || { + Builder::new().name(format!("socket-{:02}", i + 1)).spawn(move || { network::run_socket_worker( config, i, @@ -57,7 +58,7 @@ pub fn run(config: Config) -> anyhow::Result<()> { out_message_receiver, opt_tls_acceptor ); - }); + })?; } // Wait for socket worker statuses. On error from any, quit program. @@ -96,14 +97,14 @@ pub fn run(config: Config) -> anyhow::Result<()> { let config = config.clone(); let state = state.clone(); - ::std::thread::spawn(move || { + Builder::new().name("request".to_string()).spawn(move || { handler::run_request_worker( config, state, in_message_receiver, out_message_sender, ); - }); + })?; } loop {