pub struct TcpListener(/* private fields */);Expand description
A TCP socket server, listening for connections.
You can accept a new connection by using the TcpListener::accept method.
A TcpListener is created by calling TcpListener::bind.
Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub async fn bind(addr: SocketAddr) -> Result<Self>
pub async fn bind(addr: SocketAddr) -> Result<Self>
Creates a new TcpListener bound to the specified address.
The returned listener is ready for accepting connections.
Sourcepub async fn accept(&self) -> Result<(TcpStream, SocketAddr)>
pub async fn accept(&self) -> Result<(TcpStream, SocketAddr)>
Accepts a new incoming connection.
This method will block until a new connection is established.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address of this listener.
Trait Implementations§
Source§impl AsFd for TcpListener
impl AsFd for TcpListener
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
Source§impl AsRawFd for TcpListener
impl AsRawFd for TcpListener
Source§impl Debug for TcpListener
impl Debug for TcpListener
Source§impl From<TcpListener> for TcpListener
impl From<TcpListener> for TcpListener
Source§fn from(listener: TcpListener) -> Self
fn from(listener: TcpListener) -> Self
Converts to this type from the input type.
Source§impl Unwrap for TcpListener
impl Unwrap for TcpListener
type StdImpl = TcpListener
type TokioImpl = TcpListener
Source§fn unwrap_std(self) -> Self::StdImpl
fn unwrap_std(self) -> Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type.
Source§fn unwrap_tokio(self) -> Self::TokioImpl
fn unwrap_tokio(self) -> Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type.
Source§fn unwrap_std_ref(&self) -> &Self::StdImpl
fn unwrap_std_ref(&self) -> &Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type as a reference.
Source§fn unwrap_tokio_ref(&self) -> &Self::TokioImpl
fn unwrap_tokio_ref(&self) -> &Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type as a reference.
Source§fn unwrap_std_mut(&mut self) -> &mut Self::StdImpl
fn unwrap_std_mut(&mut self) -> &mut Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type as a mutable reference.
Source§fn unwrap_tokio_mut(&mut self) -> &mut Self::TokioImpl
fn unwrap_tokio_mut(&mut self) -> &mut Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type as a mutable reference.
Source§fn get_std(self) -> Option<Self::StdImpl>
fn get_std(self) -> Option<Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type.
Source§fn get_tokio(self) -> Option<Self::TokioImpl>
fn get_tokio(self) -> Option<Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type.
Source§fn get_std_ref(&self) -> Option<&Self::StdImpl>
fn get_std_ref(&self) -> Option<&Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type as a reference.
Source§fn get_tokio_ref(&self) -> Option<&Self::TokioImpl>
fn get_tokio_ref(&self) -> Option<&Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type as a reference.
Source§fn get_std_mut(&mut self) -> Option<&mut Self::StdImpl>
fn get_std_mut(&mut self) -> Option<&mut Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type as a mutable reference.
Source§fn get_tokio_mut(&mut self) -> Option<&mut Self::TokioImpl>
fn get_tokio_mut(&mut self) -> Option<&mut Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type as a mutable reference.
Auto Trait Implementations§
impl Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnwindSafe for TcpListener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more