distributed_physics_test/src/net/socket.rs
Michael Bradley cb64878186
Rename types to queues
I mean that name just sucked
2025-06-02 23:58:56 -04:00

28 lines
828 B
Rust

use std::{
io::Result,
net::{Ipv6Addr, UdpSocket},
time::Duration,
};
use crossbeam_channel::unbounded;
use super::{
queues::{ReceiveQueue, SendQueue},
thread::{start_receive_thread, start_send_thread},
};
fn configure_socket(socket: &UdpSocket) -> Result<()> {
socket.set_read_timeout(None)?;
socket.set_write_timeout(Some(Duration::from_secs(1)))?;
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))
}