This commit is contained in:
2025-12-14 18:41:56 +01:00
parent 7a135028ac
commit 18e5b027bc
3 changed files with 2279 additions and 1182 deletions

View File

@@ -8,11 +8,15 @@ edition = "2024"
# to make the lib name unique and wouldn't conflict with the bin name. # to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519 # This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "ox_speak_server_lib" name = "ox_speak_server_lib"
crate-type = ["staticlib", "cdylib", "rlib"] crate-type = ["rlib"]
[workspace] [workspace]
members = [".", "migration"] members = [".", "migration"]
[profile.dev]
debug = 1 # au lieu de 2 (par défaut) -> PDB beaucoup plus petit
incremental = true # utile pour la rapidité, pas toujours pour la RAM mais aide souvent
[profile.release] [profile.release]
#debug = true #debug = true
# poid minimal, rapidité baissé # poid minimal, rapidité baissé

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@ use std::io;
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use parking_lot::RwLock; use parking_lot::RwLock;
use tokio::task; use tokio::task;
use crate::utils::toolbox::number_of_cpus;
#[derive(Clone)] #[derive(Clone)]
pub struct UDPServer { pub struct UDPServer {
@@ -44,7 +45,7 @@ impl UDPServer {
let mut workers = Vec::new(); let mut workers = Vec::new();
for id in available_parallelism() { for id in 0..number_of_cpus() {
let bind_addr = self.bind_addr.clone(); let bind_addr = self.bind_addr.clone();
let domain = match bind_addr { let domain = match bind_addr {
@@ -60,6 +61,7 @@ impl UDPServer {
let std_sock = std::net::UdpSocket::from(sock); let std_sock = std::net::UdpSocket::from(sock);
std_sock.set_nonblocking(true)?; std_sock.set_nonblocking(true)?;
let udp = UdpSocket::from_std(std_sock)?; let udp = UdpSocket::from_std(std_sock)?;
let udp = Arc::new(udp);
let buffer_size = 1500; let buffer_size = 1500;
let worker = task::spawn(async move { let worker = task::spawn(async move {
@@ -81,13 +83,14 @@ impl UDPServer {
async fn run_windows(&self) -> io::Result<()> { async fn run_windows(&self) -> io::Result<()> {
let udp = UdpSocket::bind(self.bind_addr).await?; let udp = UdpSocket::bind(self.bind_addr).await?;
let udp = Arc::new(udp); let udp = Arc::new(udp);
let mut workers = Vec::with_capacity(self.workers); let mut workers = Vec::new();
for id in 0..self.workers { for id in 0..number_of_cpus() {
let sock = udp.clone(); let sock = udp.clone();
let buf_size = 1500; let buffer_size = 1500;
let worker = task::spawn(async move { let worker = task::spawn(async move {
if let Err(e) = Self::worker_loop(udp, buffer_size) { if let Err(e) = Self::worker_loop(sock, buffer_size).await {
eprintln!("Worker loop error: {}", e); eprintln!("Worker loop error: {}", e);
} }
}); });
@@ -100,7 +103,7 @@ impl UDPServer {
Ok(()) Ok(())
} }
async fn worker_loop(socket: UdpSocket, buffer_size: usize) -> io::Result<()>{ async fn worker_loop(socket: Arc<UdpSocket>, buffer_size: usize) -> io::Result<()>{
let mut buffer = vec![0u8; buffer_size]; let mut buffer = vec![0u8; buffer_size];
loop { loop {
let (size, peer) = socket.recv_from(&mut buffer).await?; let (size, peer) = socket.recv_from(&mut buffer).await?;