Struct otter::prelude::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
type Conn = UnixStream
type Conn = UnixStream
The type represeting the stream connection returned by accept_unix_addr()
.
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>
[src]
pub fn accept_unix_addr(
&self
) -> Result<(<UnixListener as UnixListenerExt>::Conn, UnixSocketAddr), Error>
[src]Accepts a connection and returns the client’s address as
an uds::UnixSocketAddr
. Read more
Returns the address this socket is listening on.
Auto Trait Implementations
impl RefUnwindSafe for UnixListener
impl Send for UnixListener
impl Sync for UnixListener
impl Unpin for UnixListener
impl UnwindSafe for UnixListener
Blanket Implementations
Mutably borrows from an owned value. Read more
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
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
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
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]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>,
[src]
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>,
[src]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
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]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>,
[src]
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>,
[src]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
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V