Skip to content

Commit 84aaeeb

Browse files
RandyLambertti-chi-botYangKeaoHexilee
committed
[Feat] Change to unix domain socket
* Use use tokio::net::UnixListener instead of tokio::net::Unix for unix socket communication Signed-off-by: shouxunsun <[email protected]> Co-authored-by: Ti Chi Robot <[email protected]> Co-authored-by: Yang Keao <[email protected]> Co-authored-by: xixi <[email protected]>
1 parent a7c97cd commit 84aaeeb

File tree

1 file changed

+18
-10
lines changed
  • chaos-tproxy-controller/src/cmd/interactive

1 file changed

+18
-10
lines changed

chaos-tproxy-controller/src/cmd/interactive/handler.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::task::{Context, Poll};
77
use anyhow::Error;
88
use futures::TryStreamExt;
99
use http::{Method, Request, Response, StatusCode};
10-
use hyper::server::conn::{Connection, Http};
10+
use hyper::server::conn::{Http};
1111
use hyper::service::Service;
1212
use hyper::Body;
1313
use tokio::select;
@@ -16,7 +16,9 @@ use tokio::sync::Mutex;
1616
use tokio::task::JoinHandle;
1717
use tracing::instrument;
1818

19-
use crate::cmd::interactive::stdio::StdStream;
19+
use tokio::net::{UnixListener};
20+
#[cfg(unix)]
21+
use std::os::unix::io::{FromRawFd};
2022
use crate::proxy::config::Config;
2123
use crate::proxy::exec::Proxy;
2224
use crate::raw_config::RawConfig;
@@ -43,21 +45,27 @@ impl ConfigServer {
4345
pub fn serve_interactive(&mut self) {
4446
let mut rx = self.rx.take().unwrap();
4547
let mut service = ConfigService(self.proxy.clone());
48+
4649
self.task = Some(tokio::spawn(async move {
47-
let rx_mut = &mut rx;
50+
let rx_mut = &mut rx;
51+
let unix_listener = UnixListener::from_std(unsafe {std::os::unix::net::UnixListener::from_raw_fd(3)}).unwrap();
52+
4853
loop {
49-
let stream = StdStream::default();
50-
let mut conn = Http::new().serve_connection(stream, &mut service);
51-
let conn_mut = &mut conn;
5254
select! {
5355
_ = &mut *rx_mut => {
5456
tracing::trace!("catch signal in config server.");
55-
Connection::graceful_shutdown(Pin::new(conn_mut));
5657
return Ok(());
5758
},
58-
ret = &mut *conn_mut => if let Err(e) = ret {
59-
tracing::error!("{}",e);
60-
}
59+
stream = unix_listener.accept() => {
60+
let (stream, _) = stream.unwrap();
61+
62+
let http = Http::new();
63+
let conn = http.serve_connection(stream, &mut service);
64+
if let Err(e) = conn.await {
65+
tracing::error!("{}",e);
66+
return Err(anyhow::anyhow!("{}",e));
67+
}
68+
},
6169
};
6270
}
6371
}));

0 commit comments

Comments
 (0)