From 99aeb2222988b8fa1487aa424fcf4aa3f9e51525 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Thu, 12 Dec 2024 06:31:23 +0000 Subject: [PATCH] Use &self instead of &mut self for poll_accept --- src/listener.rs | 8 ++++---- tests/vsock.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/listener.rs b/src/listener.rs index c776ba6..efd3f97 100644 --- a/src/listener.rs +++ b/src/listener.rs @@ -77,13 +77,13 @@ impl VsockListener { } /// Accepts a new incoming connection to this listener. - pub async fn accept(&mut self) -> Result<(VsockStream, VsockAddr)> { + pub async fn accept(&self) -> Result<(VsockStream, VsockAddr)> { poll_fn(|cx| self.poll_accept(cx)).await } /// Attempt to accept a connection and create a new connected socket if /// successful. - pub fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll> { + pub fn poll_accept(&self, cx: &mut Context<'_>) -> Poll> { let (inner, addr) = ready!(self.poll_accept_std(cx))?; let inner = VsockStream::new(inner)?; @@ -93,7 +93,7 @@ impl VsockListener { /// Attempt to accept a connection and create a new connected socket if /// successful. pub fn poll_accept_std( - &mut self, + &self, cx: &mut Context<'_>, ) -> Poll> { loop { @@ -162,7 +162,7 @@ impl Incoming { impl Stream for Incoming { type Item = Result; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let (socket, _) = ready!(self.inner.poll_accept(cx))?; Poll::Ready(Some(Ok(socket))) } diff --git a/tests/vsock.rs b/tests/vsock.rs index e52b9af..5521d0b 100644 --- a/tests/vsock.rs +++ b/tests/vsock.rs @@ -98,7 +98,7 @@ async fn split_vsock() { const PORT: u32 = 8002; let addr = VsockAddr::new(tokio_vsock::VMADDR_CID_LOCAL, PORT); - let mut listener = VsockListener::bind(addr).expect("connection failed"); + let listener = VsockListener::bind(addr).expect("connection failed"); let handle = tokio::task::spawn(async move { let (mut stream, _) = listener @@ -148,7 +148,7 @@ async fn into_split_vsock() { const PORT: u32 = 8001; let addr = VsockAddr::new(tokio_vsock::VMADDR_CID_LOCAL, PORT); - let mut listener = VsockListener::bind(addr).expect("connection failed"); + let listener = VsockListener::bind(addr).expect("connection failed"); let handle = tokio::task::spawn(async move { let (mut stream, _) = listener