add support for multithread buffer sending
This commit is contained in:
parent
3b61210761
commit
d0e86603ae
4 changed files with 32 additions and 20 deletions
BIN
audios/rickroll.mp3
Normal file
BIN
audios/rickroll.mp3
Normal file
Binary file not shown.
|
|
@ -1,5 +1,6 @@
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
use std::thread;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use std::{fs::File, io::Write};
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
|
|
@ -34,6 +35,9 @@ impl Dispatcher {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let source = source.clone();
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
let mut sock = TcpStream::connect(addr).expect("Failed to connect");
|
let mut sock = TcpStream::connect(addr).expect("Failed to connect");
|
||||||
|
|
||||||
while offset < duration {
|
while offset < duration {
|
||||||
|
|
@ -55,6 +59,7 @@ impl Dispatcher {
|
||||||
let buf = bincode::serialize(&msg).expect("Failed to serialize");
|
let buf = bincode::serialize(&msg).expect("Failed to serialize");
|
||||||
sock.write_all(&buf).unwrap();
|
sock.write_all(&buf).unwrap();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ mod ui_app;
|
||||||
|
|
||||||
fn main() -> eframe::Result {
|
fn main() -> eframe::Result {
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default().with_inner_size([1000.0, 1000.0]),
|
viewport: egui::ViewportBuilder::default().with_inner_size([700.0, 400.0]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,15 +46,22 @@ impl eframe::App for UIApp {
|
||||||
if ui.button("Add address").clicked() {
|
if ui.button("Add address").clicked() {
|
||||||
self.addresses.push("localhost:3000".to_owned());
|
self.addresses.push("localhost:3000".to_owned());
|
||||||
}
|
}
|
||||||
|
ui.add_space(25.0);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
ui.add_space(25.0);
|
||||||
|
|
||||||
if ui.button("Pick file").clicked() {
|
if ui.button("Pick file").clicked() {
|
||||||
if let Some(file) = FileDialog::new().set_directory("/").pick_file() {
|
let file = FileDialog::new().pick_file();
|
||||||
self.picked_file = Some(file);
|
if !file.is_none() {
|
||||||
|
self.picked_file = file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.label(format!("Picked file: {:?}", self.picked_file));
|
ui.label(format!("Picked file: {:?}", self.picked_file));
|
||||||
|
|
||||||
|
ui.add_space(25.0);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
ui.add_space(25.0);
|
||||||
|
|
||||||
if ui.button("Play sound").clicked() {
|
if ui.button("Play sound").clicked() {
|
||||||
if let Some(path) = &self.picked_file {
|
if let Some(path) = &self.picked_file {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue