pub struct UnixListener { /* fields omitted */ }
A Unix socket which can accept connections from other Unix sockets.
#![feature(async_await, await_macro, futures_api)]
use romio::uds::{UnixListener, UnixStream};
use futures::prelude::*;
async fn say_hello(mut stream: UnixStream) {
await!(stream.write_all(b"Shall I hear more, or shall I speak at this?!"));
}
async fn listen() -> Result<(), Box<dyn std::error::Error + 'static>> {
let listener = UnixListener::bind("/tmp/sock")?;
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
await!(say_hello(stream?));
}
Ok(())
}
Creates a new UnixListener
bound to the specified path.
Create a Unix Domain Socket on /tmp/sock
.
use romio::uds::UnixListener;
let socket = UnixListener::bind("/tmp/sock")?;
Returns the local socket address of this listener.
use romio::uds::UnixListener;
let socket = UnixListener::bind("/tmp/sock")?;
let addr = socket.local_addr()?;
Returns the value of the SO_ERROR
option.
use romio::uds::UnixListener;
let listener = UnixListener::bind("/tmp/sock")?;
if let Ok(Some(err)) = listener.take_error() {
println!("Got error: {:?}", err);
}
Consumes this listener, returning a stream of the sockets this listener
accepts.
This method returns an implementation of the Stream
trait which
resolves to the sockets the are accepted on this listener.
#![feature(async_await, await_macro, futures_api)]
use romio::uds::UnixListener;
use futures::prelude::*;
let listener = UnixListener::bind("/tmp/sock")?;
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
match stream {
Ok(stream) => {
println!("new client!");
},
Err(e) => { }
}
}
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static