Commit 40866e53 authored by nanamicat's avatar nanamicat

config

parent dc799bee
Pipeline #41952 passed with stages
in 2 minutes and 14 seconds
......@@ -68,7 +68,8 @@ fn main() -> Result<()> {
.unique_by(|r| r.config.src_port)
{
s.spawn(|s| {
// accept 出错直接 panic
// listen 或 accept 出错直接 panic
router.listen_tcp().unwrap();
loop {
let (connection, _) = router.socket.accept().unwrap();
s.spawn(move |_| {
......
......@@ -88,22 +88,19 @@ impl Router {
}
Ok(result)
}
Schema::TCP => {
if config.dst_port == 0 {
// listener
let result = Socket::new(config.family, Type::STREAM, Some(Protocol::TCP))?;
let addr = Router::bind_addr(config);
result.bind(&addr)?;
result.listen(100)?;
Ok(result)
} else {
// tcp client 初始化时不创建 socket,在循环里使用 connect_tcp 来创建
Ok(unsafe { Socket::from_raw_fd(0) })
}
}
Schema::TCP => Ok(unsafe { Socket::from_raw_fd(0) }),
}
}
pub fn listen_tcp(&self) -> Result<Socket> {
// listener
let result = Socket::new(self.config.family, Type::STREAM, Some(Protocol::TCP))?;
let addr = Router::bind_addr(&self.config);
result.bind(&addr)?;
result.listen(100)?;
Ok(result)
}
pub fn connect_tcp(&self) -> Result<Socket> {
// tcp client 的 socket 不要在初始化时创建,在循环里创建
// 创建 socket 和 获取 endpoint 失败会 panic,连接失败会 error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment