[−][src]Struct interprocess::local_socket::LocalSocketListener

pub struct LocalSocketListener { /* fields omitted */ }

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<'_>ⓘ

Notable traits for Incoming<'_>

impl Iterator for Incoming<'_> type Item = Result<LocalSocketStream>;
[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]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.