mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
clean up socket2 networkwork code to do more on the socket2 before convertig it.
This commit is contained in:
parent
2528afafdd
commit
97a58f0e14
@ -95,19 +95,20 @@ impl Protocols {
|
|||||||
c2s_protocol_s: mpsc::UnboundedSender<(Self, Cid)>,
|
c2s_protocol_s: mpsc::UnboundedSender<(Self, Cid)>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
use socket2::{Domain, Socket, Type};
|
use socket2::{Domain, Socket, Type};
|
||||||
use tokio::net::TcpSocket;
|
|
||||||
let domain = Domain::for_address(addr);
|
let domain = Domain::for_address(addr);
|
||||||
let socket2_socket = Socket::new(domain, Type::STREAM, None)?;
|
let socket2_socket = Socket::new(domain, Type::STREAM, None)?;
|
||||||
if domain == Domain::IPV6 {
|
if domain == Domain::IPV6 {
|
||||||
socket2_socket.set_only_v6(true)?
|
socket2_socket.set_only_v6(true)?
|
||||||
}
|
}
|
||||||
socket2_socket.set_nonblocking(true)?; //needed by tokio
|
socket2_socket.set_nonblocking(true)?; // Needed by Tokio
|
||||||
let socket = TcpSocket::from_std_stream(socket2_socket.into());
|
|
||||||
// See https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html
|
// See https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
socket.set_reuseaddr(true)?;
|
socket2_socket.set_reuse_address(true)?;
|
||||||
socket.bind(addr)?;
|
let socket2_addr = addr.into();
|
||||||
let listener = socket.listen(1024)?;
|
socket2_socket.bind(&socket2_addr)?;
|
||||||
|
socket2_socket.listen(1024)?;
|
||||||
|
let std_listener: std::net::TcpListener = socket2_socket.into();
|
||||||
|
let listener = tokio::net::TcpListener::from_std(std_listener)?;
|
||||||
trace!(?addr, "Tcp Listener bound");
|
trace!(?addr, "Tcp Listener bound");
|
||||||
let mut end_receiver = s2s_stop_listening_r.fuse();
|
let mut end_receiver = s2s_stop_listening_r.fuse();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
Loading…
Reference in New Issue
Block a user