feat: support ToSocketAddrs, not just 1 SocketAddr

This commit is contained in:
Mark 2025-03-11 22:11:36 +01:00
parent b8e729d81c
commit bf100f38e3
3 changed files with 13 additions and 12 deletions

View File

@ -2,7 +2,7 @@
use std::{
io::{BufReader, Write},
net::{SocketAddr, TcpStream},
net::TcpStream,
path::PathBuf,
sync::{Arc, Mutex},
thread,
@ -65,7 +65,7 @@ mod textcfg;
#[derive(Parser, Debug)]
struct Args {
/// the address to be used for the tcp connection to the server
addr: SocketAddr,
addr: String,
/// what to do
#[command(subcommand)]
mode: Mode,
@ -109,8 +109,8 @@ fn main() {
// parse args
let args = Args::parse();
// start
let addr = args.addr;
let mut con = TcpStream::connect(addr).unwrap();
let addr = args.addr.clone();
let mut con = TcpStream::connect(&addr).unwrap();
let mode = args.mode;
writeln!(con, "main").unwrap();
let database = Arc::new(Mutex::new(Database::new_clientside()));
@ -130,6 +130,7 @@ fn main() {
let database = Arc::clone(&database);
let mut con = con.try_clone().unwrap();
// this is all you need to keep the db in sync
let addr = addr.clone();
thread::spawn(move || {
#[cfg(feature = "playback")]
#[cfg(not(feature = "speedy2d"))]
@ -182,7 +183,7 @@ fn main() {
break 'ifstatementworkaround;
}
let mut db = database.lock().unwrap();
let client_con: Box<dyn ClientIo> = Box::new(TcpStream::connect(addr).unwrap());
let client_con: Box<dyn ClientIo> = Box::new(TcpStream::connect(&addr).unwrap());
db.remote_server_as_song_file_source = Some(Arc::new(Mutex::new(
musicdb_lib::server::get::Client::new(BufReader::new(client_con)).unwrap(),
)));
@ -222,7 +223,7 @@ fn main() {
let get_con: Arc<Mutex<musicdb_lib::server::get::Client<Box<dyn ClientIo + 'static>>>> =
Arc::new(Mutex::new(
musicdb_lib::server::get::Client::new(BufReader::new(Box::new(
TcpStream::connect(addr).expect("opening get client connection"),
TcpStream::connect(&addr).expect("opening get client connection"),
) as _))
.expect("initializing get client connection"),
));

View File

@ -2,7 +2,7 @@ pub mod get;
use std::{
io::{BufRead as _, BufReader, Read, Write},
net::{SocketAddr, TcpListener},
net::TcpListener,
sync::{mpsc, Arc, Mutex},
thread,
time::Duration,
@ -269,7 +269,7 @@ impl Command {
/// c) re-encode all received messages using Command::to_bytes_vec(), send them to the db, and send them to all your clients.
pub fn run_server(
database: Arc<Mutex<Database>>,
addr_tcp: Option<SocketAddr>,
addr_tcp: Option<String>,
sender_sender: Option<Box<dyn FnOnce(mpsc::Sender<(Command, Option<u64>)>)>>,
play_audio: bool,
) {
@ -277,7 +277,7 @@ pub fn run_server(
}
pub fn run_server_caching_thread_opt(
database: Arc<Mutex<Database>>,
addr_tcp: Option<SocketAddr>,
addr_tcp: Option<String>,
sender_sender: Option<Box<dyn FnOnce(mpsc::Sender<(Command, Option<u64>)>)>>,
caching_thread: Option<Box<dyn FnOnce(&mut crate::data::cache_manager::CacheManager)>>,
play_audio: bool,

View File

@ -18,7 +18,7 @@ use musicdb_lib::data::database::Database;
struct Args {
/// optional address for tcp connections to the server
#[arg(long)]
tcp: Option<SocketAddr>,
tcp: Option<String>,
/// optional address on which to start a website which can be used on devices without `musicdb-client` to control playback.
/// requires the `assets/` folder to be present!
#[arg(long)]
@ -65,7 +65,7 @@ enum Source {
Remote {
/// The address of another musicdb-server from where to load the songs
#[arg()]
addr: SocketAddr,
addr: String,
},
}
// struct Args {
@ -80,7 +80,7 @@ enum Source {
// init: bool,
// /// optional address for tcp connections to the server
// #[arg(long)]
// tcp: Option<SocketAddr>,
// tcp: Option<String>,
// /// optional address on which to start a website which can be used on devices without `musicdb-client` to control playback.
// /// requires the `assets/` folder to be present!
// #[arg(long)]