Struct tokio_seqpacket::UnixSeqpacket
source · 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
impl UnixSeqpacket
sourcepub async fn connect<P: AsRef<Path>>(address: P) -> Result<Self>
pub async fn connect<P: AsRef<Path>>(address: P) -> Result<Self>
Connect a new seqpacket socket to the given address.
sourcepub fn pair() -> Result<(Self, Self)>
pub fn pair() -> Result<(Self, Self)>
Create a pair of connected seqpacket sockets.
sourcepub unsafe fn from_raw_fd(fd: RawFd) -> Result<Self>
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.
sourcepub fn as_raw_fd(&self) -> RawFd
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
.
sourcepub fn into_raw_fd(self) -> RawFd
pub fn into_raw_fd(self) -> RawFd
Deregister the socket from the tokio runtime and return the inner file descriptor.
sourcepub fn as_async_fd(&self) -> &AsyncFd<FileDesc>
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();
sourcepub fn peer_cred(&self) -> Result<UCred>
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.
sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Get and clear the value of the SO_ERROR
option.
sourcepub fn poll_send(
&self,
cx: &mut Context<'_>,
buffer: &[u8]
) -> Poll<Result<usize>>
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.
sourcepub fn poll_send_vectored(
&self,
cx: &mut Context<'_>,
buffer: &[IoSlice<'_>]
) -> Poll<Result<usize>>
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.
sourcepub fn poll_send_vectored_with_ancillary(
&self,
cx: &mut Context<'_>,
buffer: &[IoSlice<'_>],
ancillary: &mut AncillaryMessageWriter<'_>
) -> Poll<Result<usize>>
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.
sourcepub async fn send(&self, buffer: &[u8]) -> Result<usize>
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.
sourcepub async fn send_vectored(&self, buffer: &[IoSlice<'_>]) -> Result<usize>
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.
sourcepub async fn send_vectored_with_ancillary(
&self,
buffer: &[IoSlice<'_>],
ancillary: &mut AncillaryMessageWriter<'_>
) -> Result<usize>
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.
sourcepub fn poll_recv(
&self,
cx: &mut Context<'_>,
buffer: &mut [u8]
) -> Poll<Result<usize>>
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.
sourcepub fn poll_recv_vectored(
&self,
cx: &mut Context<'_>,
buffer: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize>>
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.
sourcepub fn poll_recv_vectored_with_ancillary<'a>(
&self,
cx: &mut Context<'_>,
buffer: &mut [IoSliceMut<'_>],
ancillary_buffer: &'a mut [u8]
) -> Poll<Result<(usize, AncillaryMessageReader<'a>)>>
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.
sourcepub async fn recv(&self, buffer: &mut [u8]) -> Result<usize>
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.
sourcepub async fn recv_vectored(
&self,
buffer: &mut [IoSliceMut<'_>]
) -> Result<usize>
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.
sourcepub async fn recv_vectored_with_ancillary<'a>(
&self,
buffer: &mut [IoSliceMut<'_>],
ancillary_buffer: &'a mut [u8]
) -> Result<(usize, AncillaryMessageReader<'a>)>
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.