Skip to content

Commit

Permalink
net: make UnixListener::poll_accept public (#2880)
Browse files Browse the repository at this point in the history
This makes it consistent with `TcpListener::poll_accept` and other
public poll methods the library provides. This particular method is
useful for writing generic code that accepts connections since async
functions can't easily be used with traits. It is possible to
generically accept connections with `Incoming`, however, this doesn't
return the incoming `SocketAddr`.
  • Loading branch information
kalcutter authored Sep 25, 2020
1 parent c0c7124 commit a517dbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tokio/src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ impl TcpListener {
poll_fn(|cx| self.poll_accept(cx)).await
}

/// Attempts to poll `SocketAddr` and `TcpStream` bound to this address.
/// Polls to accept a new incoming connection to this listener.
///
/// In case if I/O resource isn't ready yet, `Poll::Pending` is returned and
/// current task will be notified by a waker.
/// If there is no connection to accept, `Poll::Pending` is returned and
/// the current task will be notified by a waker.
pub fn poll_accept(
&mut self,
cx: &mut Context<'_>,
Expand Down
6 changes: 5 additions & 1 deletion tokio/src/net/unix/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ impl UnixListener {
poll_fn(|cx| self.poll_accept(cx)).await
}

pub(crate) fn poll_accept(
/// Polls to accept a new incoming connection to this listener.
///
/// If there is no connection to accept, `Poll::Pending` is returned and
/// the current task will be notified by a waker.
pub fn poll_accept(
&mut self,
cx: &mut Context<'_>,
) -> Poll<io::Result<(UnixStream, SocketAddr)>> {
Expand Down

0 comments on commit a517dbf

Please sign in to comment.