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

Method new

libs/hbb_common/src/tcp.rs:83–110  ·  view source on GitHub ↗
(
        remote_addr: T,
        local_addr: Option<SocketAddr>,
        ms_timeout: u64,
    )

Source from the content-addressed store, hash-verified

81
82impl FramedStream {
83 pub async fn new<T: ToSocketAddrs + std::fmt::Display>(
84 remote_addr: T,
85 local_addr: Option<SocketAddr>,
86 ms_timeout: u64,
87 ) -> ResultType<Self> {
88 for remote_addr in lookup_host(&remote_addr).await? {
89 let local = if let Some(addr) = local_addr {
90 addr
91 } else {
92 crate::config::Config::get_any_listen_addr(remote_addr.is_ipv4())
93 };
94 if let Ok(socket) = new_socket(local, true) {
95 if let Ok(Ok(stream)) =
96 super::timeout(ms_timeout, socket.connect(remote_addr)).await
97 {
98 stream.set_nodelay(true).ok();
99 let addr = stream.local_addr()?;
100 return Ok(Self(
101 Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()),
102 addr,
103 None,
104 0,
105 ));
106 }
107 }
108 }
109 bail!(format!("Failed to connect to {remote_addr}"));
110 }
111
112 pub async fn connect<'t, T>(
113 target: T,

Callers

nothing calls this directly

Calls 5

timeoutFunction · 0.85
DynTcpStreamClass · 0.85
new_socketFunction · 0.70
connectMethod · 0.45
local_addrMethod · 0.45

Tested by

no test coverage detected