Struct otter_api_tests::unix::net::UnixListener 1.10.0[−][src]
pub struct UnixListener(_);
Expand description
A structure representing a Unix domain socket server.
Examples
use std::thread; use std::os::unix::net::{UnixStream, UnixListener}; fn handle_client(stream: UnixStream) { // ... } fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; // accept connections and process them, spawning a new thread for each one for stream in listener.incoming() { match stream { Ok(stream) => { /* connection succeeded */ thread::spawn(|| handle_client(stream)); } Err(err) => { /* connection failed */ break; } } } Ok(()) }
Implementations
Creates a new UnixListener bound to the specified socket.
Examples
use std::os::unix::net::UnixListener; let listener = match UnixListener::bind("/path/to/the/socket") { Ok(sock) => sock, Err(e) => { println!("Couldn't connect: {:?}", e); return } };
Accepts a new incoming connection to this listener.
This function will block the calling thread until a new Unix connection
is established. When established, the corresponding UnixStream and
the remote peer’s address will be returned.
Examples
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; match listener.accept() { Ok((socket, addr)) => println!("Got a client: {:?}", addr), Err(e) => println!("accept function failed: {:?}", e), } Ok(()) }
Creates a new independently owned handle to the underlying socket.
The returned UnixListener is a reference to the same socket that this
object references. Both handles can be used to accept incoming
connections and options set on one listener will affect the other.
Examples
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; let listener_copy = listener.try_clone().expect("try_clone failed"); Ok(()) }
Returns the local socket address of this listener.
Examples
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; let addr = listener.local_addr().expect("Couldn't get local address"); Ok(()) }
Moves the socket into or out of nonblocking mode.
This will result in the accept operation becoming nonblocking,
i.e., immediately returning from their calls. If the IO operation is
successful, Ok is returned and no further action is required. If the
IO operation could not be completed and needs to be retried, an error
with kind io::ErrorKind::WouldBlock is returned.
Examples
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; listener.set_nonblocking(true).expect("Couldn't set non blocking"); Ok(()) }
Returns the value of the SO_ERROR option.
Examples
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/tmp/sock")?; if let Ok(Some(err)) = listener.take_error() { println!("Got error: {:?}", err); } Ok(()) }
Platform specific
On Redox this always returns None.
Returns an iterator over incoming connections.
The iterator will never return None and will also not yield the
peer’s SocketAddr structure.
Examples
use std::thread; use std::os::unix::net::{UnixStream, UnixListener}; fn handle_client(stream: UnixStream) { // ... } fn main() -> std::io::Result<()> { let listener = UnixListener::bind("/path/to/the/socket")?; for stream in listener.incoming() { match stream { Ok(stream) => { thread::spawn(|| handle_client(stream)); } Err(err) => { break; } } } Ok(()) }
Trait Implementations
Constructs a new instance of Self from the given raw file
descriptor. Read more
type Item = Result<UnixStream, Error>
type Item = Result<UnixStream, Error>The type of the elements being iterated over.
Consumes this object, returning the raw underlying file descriptor. Read more
impl TryFrom<UnixListener> for UnixListener
impl TryFrom<UnixListener> for UnixListenerpub fn try_from(stream: UnixListener) -> Result<UnixListener, Error>
pub fn try_from(stream: UnixListener) -> Result<UnixListener, Error>Consumes stream, returning the tokio I/O object.
This is equivalent to
UnixListener::from_std(stream).
impl UnixListenerExt for UnixListener
impl UnixListenerExt for UnixListenertype Conn = UnixStream
type Conn = UnixStreamThe type represeting the stream connection returned by accept_unix_addr().
pub fn bind_unix_addr(on: &UnixSocketAddr) -> Result<UnixListener, Error>
pub fn bind_unix_addr(on: &UnixSocketAddr) -> Result<UnixListener, Error>Creates a socket bound to a UnixSocketAddr and starts listening on it.
pub fn accept_unix_addr(
&self
) -> Result<(<UnixListener as UnixListenerExt>::Conn, UnixSocketAddr), Error>
pub fn accept_unix_addr(
&self
) -> Result<(<UnixListener as UnixListenerExt>::Conn, UnixSocketAddr), Error>Accepts a connection and returns the client’s address as
an uds::UnixSocketAddr. Read more
fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>
fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>Returns the address this socket is listening on.
Auto Trait Implementations
impl RefUnwindSafe for UnixListenerimpl Send for UnixListenerimpl Sync for UnixListenerimpl Unpin for UnixListenerimpl UnwindSafe for UnixListenerBlanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read more
impl<A> DynCastExt for A
impl<A> DynCastExt for Apub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>, Use this to cast from one trait object type to another. Read more
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>, Use this to upcast a trait to one of its supertraits. Read more
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized, pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>, Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;pub fn vzip(self) -> V