Skip to content

Commit

Permalink
Use &self instead of &mut self for poll_accept
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 12, 2024
1 parent ae7a784 commit 99aeb22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<(VsockStream, VsockAddr)>> {
pub fn poll_accept(&self, cx: &mut Context<'_>) -> Poll<Result<(VsockStream, VsockAddr)>> {
let (inner, addr) = ready!(self.poll_accept_std(cx))?;
let inner = VsockStream::new(inner)?;

Expand All @@ -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<Result<(vsock::VsockStream, VsockAddr)>> {
loop {
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Incoming {
impl Stream for Incoming {
type Item = Result<VsockStream>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let (socket, _) = ready!(self.inner.poll_accept(cx))?;
Poll::Ready(Some(Ok(socket)))
}
Expand Down
4 changes: 2 additions & 2 deletions tests/vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99aeb22

Please sign in to comment.