Struct glommio::net::UnixStream
source · pub struct UnixStream<B: RxBuf = NonBuffered> { /* private fields */ }
Expand description
A Unix Stream of bytes. This can be used with AsyncRead
, AsyncBufRead
and
AsyncWrite
Implementations§
source§impl UnixStream
impl UnixStream
sourcepub fn pair() -> Result<(UnixStream, UnixStream), ()>
pub fn pair() -> Result<(UnixStream, UnixStream), ()>
Creates an unnamed pair of connected Unix stream sockets.
§Examples
use futures_lite::io::{AsyncReadExt, AsyncWriteExt};
use glommio::{net::UnixStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let (mut p1, mut p2) = UnixStream::pair().unwrap();
let sz = p1.write(&[65u8; 1]).await.unwrap();
let mut buf = [0u8; 1];
let sz = p2.read(&mut buf).await.unwrap();
})
sourcepub async fn connect<A: AsRef<Path>>(addr: A) -> Result<UnixStream, ()>
pub async fn connect<A: AsRef<Path>>(addr: A) -> Result<UnixStream, ()>
Creates a Unix connection to the specified endpoint.
§Examples
use glommio::{net::UnixStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
UnixStream::connect("/tmp/named").await.unwrap();
})
sourcepub fn buffered(self) -> UnixStream<Preallocated>
pub fn buffered(self) -> UnixStream<Preallocated>
Creates a buffered Unix connection with default receive buffer.
sourcepub fn buffered_with<B: Buffered>(self, buf: B) -> UnixStream<B>
pub fn buffered_with<B: Buffered>(self, buf: B) -> UnixStream<B>
Creates a buffered Unix connection with custom receive buffer.
source§impl<B: RxBuf> UnixStream<B>
impl<B: RxBuf> UnixStream<B>
sourcepub async fn shutdown(&self, how: Shutdown) -> Result<(), ()>
pub async fn shutdown(&self, how: Shutdown) -> Result<(), ()>
Shuts down the read, write, or both halves of this connection.
sourcepub async fn peek(&self, buf: &mut [u8]) -> Result<usize, ()>
pub async fn peek(&self, buf: &mut [u8]) -> Result<usize, ()>
Receives data on the socket from the remote address to which it is connected, without removing that data from the queue.
On success, returns the number of bytes peeked. Successive calls return the same data. This is accomplished by passing MSG_PEEK as a flag to the underlying recv system call.
sourcepub fn peer_addr(&self) -> Result<SocketAddr, ()>
pub fn peer_addr(&self) -> Result<SocketAddr, ()>
Returns the socket address of the remote peer of this Unix connection.
§Examples
use glommio::{net::UnixStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = UnixStream::connect("/tmp/named").await.unwrap();
println!("My peer: {:?}", stream.peer_addr());
})
sourcepub fn local_addr(&self) -> Result<SocketAddr, ()>
pub fn local_addr(&self) -> Result<SocketAddr, ()>
Returns the socket address of the local half of this Unix connection.
§Examples
use glommio::{net::UnixStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = UnixStream::connect("/tmp/named").await.unwrap();
println!("My peer: {:?}", stream.local_addr());
})
Trait Implementations§
source§impl<B: Buffered + Unpin> AsyncBufRead for UnixStream<B>
impl<B: Buffered + Unpin> AsyncBufRead for UnixStream<B>
source§fn poll_fill_buf<'a>(
self: Pin<&'a mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<&'a [u8]>>
fn poll_fill_buf<'a>( self: Pin<&'a mut Self>, cx: &mut Context<'_> ) -> Poll<Result<&'a [u8]>>
source§impl<B: RxBuf + Unpin> AsyncRead for UnixStream<B>
impl<B: RxBuf + Unpin> AsyncRead for UnixStream<B>
source§impl<B: RxBuf + Unpin> AsyncWrite for UnixStream<B>
impl<B: RxBuf + Unpin> AsyncWrite for UnixStream<B>
source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8] ) -> Poll<Result<usize>>
buf
into the object. Read moresource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
source§impl<B: Debug + RxBuf> Debug for UnixStream<B>
impl<B: Debug + RxBuf> Debug for UnixStream<B>
source§impl FromRawFd for UnixStream
impl FromRawFd for UnixStream
source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self
from the given raw file
descriptor. Read moreimpl<'__pin, B: RxBuf> Unpin for UnixStream<B>where
__Origin<'__pin, B>: Unpin,
Auto Trait Implementations§
impl<B = NonBuffered> !Freeze for UnixStream<B>
impl<B = NonBuffered> !RefUnwindSafe for UnixStream<B>
impl<B = NonBuffered> !Send for UnixStream<B>
impl<B = NonBuffered> !Sync for UnixStream<B>
impl<B = NonBuffered> !UnwindSafe for UnixStream<B>
Blanket Implementations§
source§impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
source§fn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
fn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
source§fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self>where
Self: Unpin,
fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self>where
Self: Unpin,
source§fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self>where
Self: Unpin,
fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self>where
Self: Unpin,
buf
until a newline (the 0xA byte) or EOF is found. Read moresource§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
source§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
source§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
source§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read moresource§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moresource§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
source§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
source§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
source§fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
source§fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
dyn AsyncWrite + Send + 'a
. Read more