Skip to content

Commit

Permalink
Refactor listen_forward_loop to continuously serve and update rpc_ser…
Browse files Browse the repository at this point in the history
…ve signature for mutable references
  • Loading branch information
nullchinchilla committed Aug 27, 2024
1 parent 2bd5af5 commit 4852801
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions binaries/geph5-bridge/src/listen_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ use smol::future::FutureExt as _;
use stdcode::StdcodeSerializeExt;
use tap::Tap;

pub async fn listen_forward_loop(my_ip: IpAddr, listener: impl Listener) {
pub async fn listen_forward_loop(my_ip: IpAddr, mut listener: impl Listener) {
let state = State {
my_ip,
mapping: Cache::builder()
.time_to_idle(Duration::from_secs(86400))
.build(),
};
nanorpc_sillad::rpc_serve(listener, BridgeControlService(state))
.await
.unwrap()
let mut service = BridgeControlService(state);
loop {
let _ = nanorpc_sillad::rpc_serve(&mut listener, &mut service).await;
}
}

#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -75,7 +76,7 @@ async fn handle_one_listener(
loop {
let client_conn = listener.accept().await?;
let count = COUNT.fetch_add(1, Ordering::Relaxed);
tracing::debug!(count, "handled a connection");
tracing::debug!(count, b2e_dest = debug(b2e_dest), "handled a connection");
let metadata = metadata.clone();
smolscale::spawn(async move {
scopeguard::defer!({
Expand Down
4 changes: 2 additions & 2 deletions libraries/nanorpc-sillad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl<D: Dialer> RpcTransport for DialerTransport<D> {

/// Runs a given nanorpc service using the given sillad listener
pub async fn rpc_serve(
mut listener: impl Listener,
service: impl RpcService,
mut listener: &mut impl Listener,
service: &mut impl RpcService,
) -> std::io::Result<()> {
let lexec = Executor::new();
lexec
Expand Down

0 comments on commit 4852801

Please sign in to comment.