MCPcopy Create free account
hub / github.com/Recordscript/recordscript / new_socket

Function new_socket

libs/hbb_common/src/tcp.rs:65–80  ·  view source on GitHub ↗
(addr: std::net::SocketAddr, reuse: bool)

Source from the content-addressed store, hash-verified

63}
64
65pub(crate) fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpSocket, std::io::Error> {
66 let socket = match addr {
67 std::net::SocketAddr::V4(..) => TcpSocket::new_v4()?,
68 std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?,
69 };
70 if reuse {
71 // windows has no reuse_port, but it's reuse_address
72 // almost equals to unix's reuse_port + reuse_address,
73 // though may introduce nondeterministic behavior
74 #[cfg(unix)]
75 socket.set_reuseport(true).ok();
76 socket.set_reuseaddr(true).ok();
77 }
78 socket.bind(addr)?;
79 Ok(socket)
80}
81
82impl FramedStream {
83 pub async fn new<T: ToSocketAddrs + std::fmt::Display>(

Callers 4

newMethod · 0.70
new_listenerFunction · 0.70
listen_anyFunction · 0.70
connectMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected