pub struct TcpListener { /* private fields */ }Expand description
One blocking IPv4 TCP listener.
The caller owns the listener and every accepted stream independently.
Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub fn bind_any(port: u16) -> Result<Self>
pub fn bind_any(port: u16) -> Result<Self>
Bind all IPv4 interfaces with the donor’s default backlog of 128.
§Errors
Returns an OA I/O error if socket creation, binding, or listening fails.
Sourcepub fn bind(host: &str, port: u16, backlog: i32) -> Result<Self>
pub fn bind(host: &str, port: u16, backlog: i32) -> Result<Self>
Bind an IPv4 host and port with an explicit positive listen backlog. A zero port asks the operating system to select an available port.
§Errors
Returns InvalidArgument for an invalid IPv4 address or backlog, or
Io for a socket failure.
Sourcepub fn accept(&self) -> Result<TcpStream>
pub fn accept(&self) -> Result<TcpStream>
Accept one connected stream.
§Errors
Returns FailedPrecondition after close, or Io for accept failure.
Sourcepub const fn local_addr(&self) -> SocketAddr
pub const fn local_addr(&self) -> SocketAddr
Return the bound address captured after listen, including an OS-selected port.
Auto Trait Implementations§
impl Forget for TcpListener
impl Freeze for TcpListenerwhere
I32NotAllOnes: Freeze,
impl Move for TcpListener
impl RefUnwindSafe for TcpListenerwhere
I32NotAllOnes: RefUnwindSafe,
impl Send for TcpListenerwhere
I32NotAllOnes: Send,
impl Sync for TcpListenerwhere
I32NotAllOnes: Sync,
impl Unpin for TcpListenerwhere
I32NotAllOnes: Unpin,
impl UnsafeUnpin for TcpListenerwhere
I32NotAllOnes: UnsafeUnpin,
impl UnwindSafe for TcpListenerwhere
I32NotAllOnes: UnwindSafe,
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