pea_2_pea/src/server/utils.rs
2025-08-01 14:06:47 +02:00

14 lines
530 B
Rust

use pea_2_pea::*;
pub fn send_general_error_to_client<T: std::error::Error>(
dst: core::net::SocketAddr,
e: T,
socket: std::sync::Arc<smol::net::UdpSocket>,
) {
let mut resp_buf: Box<[u8]> = vec![0; e.to_string().len() + 1].into_boxed_slice();
resp_buf[0] = ServerResponse::GENERAL_ERROR as u8; // set 1st byte to ERROR
resp_buf[1..1 + e.to_string().len()].copy_from_slice(e.to_string().as_bytes()); // send error text to client
let _ = socket.send_to(&[ServerResponse::GENERAL_ERROR as u8], dst);
}