Move netcode to module
All checks were successful
CI / Formatting (push) Successful in 1m5s

This commit is contained in:
Michael Bradley 2025-05-25 20:36:49 -04:00
parent c005a4dbb9
commit 9ac45e9249
Signed by: MichaelBradley
SSH key fingerprint: SHA256:o/aaeYtRubILK7OYYjYP12DmU7BsPUhKji1AgaQ+ge4
6 changed files with 210 additions and 161 deletions

27
src/net/socket.rs Normal file
View file

@ -0,0 +1,27 @@
use std::{
io::Result,
net::{Ipv6Addr, UdpSocket},
};
use crossbeam_channel::unbounded;
use super::{
thread::{start_receive_thread, start_send_thread},
types::{ReceiveQueue, SendQueue},
};
fn configure_socket(socket: &UdpSocket) -> Result<()> {
socket.set_read_timeout(None)?;
socket.set_write_timeout(None)?;
Ok(())
}
pub fn bind_socket(port: u16) -> Result<(SendQueue, ReceiveQueue)> {
let socket = UdpSocket::bind((Ipv6Addr::UNSPECIFIED, port))?;
configure_socket(&socket)?;
let (send_inbound, receive_inbound) = unbounded();
start_receive_thread(send_inbound, socket.try_clone()?);
let (send_outbound, receive_outbound) = unbounded();
start_send_thread(receive_outbound, socket);
Ok((send_outbound, receive_inbound))
}