[−][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::*}; fn handle_error(connection: io::Result<LocalSocketStream>) -> Option<LocalSocketStream> { match connection { Ok(val) => Some(val), Err(error) => { eprintln!("Incoming connection failed: {}", error); None } } } let listener = LocalSocketListener::bind("/tmp/example.sock")?; for mut connection in listener.incoming().filter_map(handle_error) { connection.write_all(b"Hello from server!")?; let mut buffer = String::new(); connection.read_to_string(&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
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream}; use std::io::{self, prelude::*}; fn handle_error(connection: io::Result<LocalSocketStream>) -> Option<LocalSocketStream> { match connection { Ok(val) => Some(val), Err(error) => { eprintln!("Incoming connection failed: {}", error); None } } } let listener = LocalSocketListener::bind("/tmp/example.sock")?; // Thanks to incoming(), you get a simple self-documenting infinite server loop for mut connection in listener.incoming().filter_map(handle_error) { eprintln!("New client!"); }
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
impl Send for LocalSocketListener
impl Sync for LocalSocketListener
impl Unpin for LocalSocketListener
impl UnwindSafe for LocalSocketListener
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,
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.
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>,