pub struct UnixSeqpacket { /* private fields */ }
Expand description

Unix seqpacket socket.

Note that there are no functions to get the local or remote address of the connection. That is because connected Unix sockets are always anonymous, which means that the address contains no useful information.

Implementations§

source§

impl UnixSeqpacket

source

pub async fn connect<P: AsRef<Path>>(address: P) -> Result<Self>

Connect a new seqpacket socket to the given address.

source

pub fn pair() -> Result<(Self, Self)>

Create a pair of connected seqpacket sockets.

source

pub unsafe fn from_raw_fd(fd: RawFd) -> Result<Self>

Wrap a raw file descriptor as UnixSeqpacket.

Registration of the file descriptor with the tokio runtime may fail. For that reason, this function returns a std::io::Result.

Safety

This function is unsafe because the socket assumes it is the sole owner of the file descriptor. Usage of this function could accidentally allow violating this contract which can cause memory unsafety in code that relies on it being true.

source

pub fn as_raw_fd(&self) -> RawFd

Get the raw file descriptor of the socket.

This is a shortcut for seqpacket.as_async_fd().as_raw_fd(). See as_async_fd.

source

pub fn into_raw_fd(self) -> RawFd

Deregister the socket from the tokio runtime and return the inner file descriptor.

source

pub fn as_async_fd(&self) -> &AsyncFd<FileDesc>

Get the async file descriptor of this object.

This can be useful for applications that want to do low-level socket calls, such as sendmsg, but still want to use async and need to know when the socket is ready to be used.

Example:

let seqpacket = tokio_seqpacket::UnixSeqpacket::connect("/tmp/example.sock").await?;
seqpacket.as_async_fd().writable().await?.retain_ready();
source

pub fn peer_cred(&self) -> Result<UCred>

Get the effective credentials of the process which called connect or pair.

Note that this is not necessarily the process that currently has the file descriptor of the other side of the connection.

source

pub fn take_error(&self) -> Result<Option<Error>>

Get and clear the value of the SO_ERROR option.

source

pub fn poll_send( &self, cx: &mut Context<'_>, buffer: &[u8] ) -> Poll<Result<usize>>

Try to send data on the socket to the connected peer without blocking.

If the socket is not ready yet, the current task is scheduled to wake up when the socket becomes writeable.

Note that unlike Self::send, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub fn poll_send_vectored( &self, cx: &mut Context<'_>, buffer: &[IoSlice<'_>] ) -> Poll<Result<usize>>

Try to send data on the socket to the connected peer without blocking.

If the socket is not ready yet, the current task is scheduled to wake up when the socket becomes writeable.

Note that unlike Self::send_vectored, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub fn poll_send_vectored_with_ancillary( &self, cx: &mut Context<'_>, buffer: &[IoSlice<'_>], ancillary: &mut AncillaryMessageWriter<'_> ) -> Poll<Result<usize>>

Try to send data with ancillary data on the socket to the connected peer without blocking.

If the socket is not ready yet, the current task is scheduled to wake up when the socket becomes writeable.

Note that unlike Self::send_vectored_with_ancillary, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub async fn send(&self, buffer: &[u8]) -> Result<usize>

Send data on the socket to the connected peer.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub async fn send_vectored(&self, buffer: &[IoSlice<'_>]) -> Result<usize>

Send data on the socket to the connected peer.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub async fn send_vectored_with_ancillary( &self, buffer: &[IoSlice<'_>], ancillary: &mut AncillaryMessageWriter<'_> ) -> Result<usize>

Send data with ancillary data on the socket to the connected peer.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub fn poll_recv( &self, cx: &mut Context<'_>, buffer: &mut [u8] ) -> Poll<Result<usize>>

Try to receive data on the socket from the connected peer without blocking.

If there is no data ready yet, the current task is scheduled to wake up when the socket becomes readable.

Note that unlike Self::recv, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub fn poll_recv_vectored( &self, cx: &mut Context<'_>, buffer: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize>>

Try to receive data on the socket from the connected peer without blocking.

If there is no data ready yet, the current task is scheduled to wake up when the socket becomes readable.

Note that unlike Self::recv_vectored, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub fn poll_recv_vectored_with_ancillary<'a>( &self, cx: &mut Context<'_>, buffer: &mut [IoSliceMut<'_>], ancillary_buffer: &'a mut [u8] ) -> Poll<Result<(usize, AncillaryMessageReader<'a>)>>

Try to receive data with ancillary data on the socket from the connected peer without blocking.

Any file descriptors received in the anicallary data will have the close-on-exec flag set. If the OS supports it, this is done atomically with the reception of the message. However, on Illumos and Solaris, the close-on-exec flag is set in a separate step after receiving the message.

Note that you should always wrap or close any file descriptors received this way. If you do not, the received file descriptors will stay open until the process is terminated.

If there is no data ready yet, the current task is scheduled to wake up when the socket becomes readable.

Note that unlike Self::recv_vectored_with_ancillary, only the last task calling this function will be woken up. For that reason, it is preferable to use the async functions rather than polling functions when possible.

source

pub async fn recv(&self, buffer: &mut [u8]) -> Result<usize>

Receive data on the socket from the connected peer.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub async fn recv_vectored( &self, buffer: &mut [IoSliceMut<'_>] ) -> Result<usize>

Receive data on the socket from the connected peer.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub async fn recv_vectored_with_ancillary<'a>( &self, buffer: &mut [IoSliceMut<'_>], ancillary_buffer: &'a mut [u8] ) -> Result<(usize, AncillaryMessageReader<'a>)>

Receive data with ancillary data on the socket from the connected peer.

Any file descriptors received in the anicallary data will have the close-on-exec flag set. If the OS supports it, this is done atomically with the reception of the message. However, on Illumos and Solaris, the close-on-exec flag is set in a separate step after receiving the message.

Note that you should always wrap or close any file descriptors received this way. If you do not, the received file descriptors will stay open until the process is terminated.

This function is safe to call concurrently from different tasks. All calling tasks will try to complete the asynchronous action, although the order in which they complete is not guaranteed.

source

pub fn shutdown(&self, how: Shutdown) -> Result<()>

Shuts down the read, write, or both halves of this connection.

This function will cause all pending and future I/O calls on the specified portions to immediately return with an appropriate value (see the documentation of Shutdown).

Trait Implementations§

source§

impl AsFd for UnixSeqpacket

source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
source§

impl AsRawFd for UnixSeqpacket

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Debug for UnixSeqpacket

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<UnixSeqpacket> for OwnedFd

source§

fn from(socket: UnixSeqpacket) -> Self

Converts to this type from the input type.
source§

impl IntoRawFd for UnixSeqpacket

source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
source§

impl TryFrom<OwnedFd> for UnixSeqpacket

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(fd: OwnedFd) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.