[−][src]Struct interprocess::local_socket::LocalSocketListener
A local socket server, listening for connections.
Example
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream}; use std::io::{self, prelude::*, BufReader}; fn handle_error(conn: io::Result<LocalSocketStream>) -> Option<LocalSocketStream> { match conn { Ok(val) => Some(val), Err(error) => { eprintln!("Incoming connection failed: {}", error); None } } } let listener = LocalSocketListener::bind("/tmp/example.sock")?; for mut conn in listener.incoming().filter_map(handle_error) { conn.write_all(b"Hello from server!\n")?; let mut conn = BufReader::new(conn); let mut buffer = String::new(); conn.read_line(&mut buffer); println!("Client answered: {}", buffer); }
Implementations
impl LocalSocketListener[src]
pub fn bind<'a>(name: impl ToLocalSocketName<'a>) -> Result<Self>[src]
Creates a socket server with the specified local socket name.
pub fn accept(&self) -> Result<LocalSocketStream>[src]
Listens for incoming connections to the socket, blocking until a client is connected.
See incoming for a convenient way to create a main loop for a server.
pub fn incoming(&self) -> Incoming<'_>ⓘ[src]
Creates an infinite iterator which calls accept() with each iteration. Used together with for loops to conveniently create a main loop for a socket server.
Example
See the struct-level documentation for a full example which already uses this method.
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>[src]
Enables or disables the nonblocking mode for the listener. By default, it is disabled.
In nonblocking mode, calling accept and iterating through incoming will immediately return a WouldBlock error if there is no client attempting to connect at the moment instead of blocking until one arrives.
Platform-specific behavior
Windows
The nonblocking mode will be also be set for the streams produced by accept and incoming, both existing and new ones.
Trait Implementations
impl Debug for LocalSocketListener[src]
impl<'a> From<&'a LocalSocketListener> for Incoming<'a>[src]
fn from(listener: &'a LocalSocketListener) -> Self[src]
Auto Trait Implementations
impl RefUnwindSafe for LocalSocketListener[src]
impl Send for LocalSocketListener[src]
impl Sync for LocalSocketListener[src]
impl Unpin for LocalSocketListener[src]
impl UnwindSafe for LocalSocketListener[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,