change signature of accept function

This commit is contained in:
John Smith 2023-12-15 16:56:31 -05:00 committed by Christien Rioux
parent d454f9fdf9
commit f47adfa03f
2 changed files with 16 additions and 8 deletions

View File

@ -456,7 +456,7 @@ impl ClientApi {
.await;
debug!(
"Closed Client API Connection: {:?} -> {:?}",
"Closed TCP Client API Connection: {:?} -> {:?}",
peer_addr, local_addr
);
@ -486,7 +486,7 @@ impl ClientApi {
self.run_json_request_processor(reader, writer, stop_token)
.await;
debug!("Closed Client API Connection",);
debug!("Closed IPC Client API Connection",);
awg.done();
}

View File

@ -100,7 +100,7 @@ impl Drop for IpcIncoming {
pub struct IpcListener {
path: Option<PathBuf>,
internal: Option<UnixListener>,
internal: Option<Arc<UnixListener>>,
}
impl IpcListener {
@ -108,14 +108,20 @@ impl IpcListener {
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<Self> {
Ok(Self {
path: Some(path.as_ref().to_path_buf()),
internal: Some(UnixListener::bind(path)?),
internal: Some(Arc::new(UnixListener::bind(path)?)),
})
}
/// Accepts a new incoming connection to this listener.
pub async fn accept(&self) -> io::Result<IpcStream> {
pub fn accept(&self) -> SendPinBoxFuture<io::Result<IpcStream>> {
let this = IpcListener {
path: self.path.clone(),
internal: self.internal.clone(),
};
Box::pin(async move {
Ok(IpcStream {
internal: self.internal.as_ref().unwrap().accept().await?.0,
internal: this.internal.as_ref().unwrap().accept().await?.0,
})
})
}
@ -123,7 +129,9 @@ impl IpcListener {
pub fn incoming(mut self) -> IpcIncoming {
IpcIncoming {
path: self.path.take().unwrap(),
internal: UnixListenerStream::new(self.internal.take().unwrap()),
internal: UnixListenerStream::new(
Arc::into_inner(self.internal.take().unwrap()).unwrap(),
),
}
}
}