This commit is contained in:
parent
c005a4dbb9
commit
9ac45e9249
6 changed files with 210 additions and 161 deletions
27
src/net/socket.rs
Normal file
27
src/net/socket.rs
Normal 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))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue