pub trait UnixStreamExt {
    // Required methods
    unsafe fn read_overlapped(
        &self,
        buf: &mut [u8],
        overlapped: *mut OVERLAPPED
    ) -> Result<Option<usize>>;
    unsafe fn write_overlapped(
        &self,
        buf: &[u8],
        overlapped: *mut OVERLAPPED
    ) -> Result<Option<usize>>;
    unsafe fn connect_overlapped(
        &self,
        addr: &SocketAddr,
        buf: &[u8],
        overlapped: *mut OVERLAPPED
    ) -> Result<Option<usize>>;
    fn connect_complete(&self) -> Result<()>;
    unsafe fn result(&self, overlapped: *mut OVERLAPPED) -> Result<(usize, u32)>;
}
Expand description

Additional methods for the UnixStream type

Required Methods§

source

unsafe fn read_overlapped( &self, buf: &mut [u8], overlapped: *mut OVERLAPPED ) -> Result<Option<usize>>

Execute an overlapped read I/O operation on this Unix domain socket stream.

This function will issue an overlapped I/O read (via WSARecv) on this socket. The provided buffer will be filled in when the operation completes and the given OVERLAPPED instance is used to track the overlapped operation.

If the operation succeeds, Ok(Some(n)) is returned indicating how many bytes were read. If the operation returns an error indicating that the I/O is currently pending, Ok(None) is returned. Otherwise, the error associated with the operation is returned and no overlapped operation is enqueued.

The number of bytes read will be returned as part of the completion notification when the I/O finishes.

Safety

This function is unsafe because the kernel requires that the buf and overlapped pointers are valid until the end of the I/O operation. The kernel also requires that overlapped is unique for this I/O operation and is not in use for any other I/O.

To safely use this function callers must ensure that these two input pointers are valid until the I/O operation is completed, typically via completion ports and waiting to receive the completion notification on the port.

source

unsafe fn write_overlapped( &self, buf: &[u8], overlapped: *mut OVERLAPPED ) -> Result<Option<usize>>

Execute an overlapped write I/O operation on this Unix domain socket stream.

This function will issue an overlapped I/O write (via WSASend) on this socket. The provided buffer will be written when the operation completes and the given OVERLAPPED instance is used to track the overlapped operation.

If the operation succeeds, Ok(Some(n)) is returned where n is the number of bytes that were written. If the operation returns an error indicating that the I/O is currently pending, Ok(None) is returned. Otherwise, the error associated with the operation is returned and no overlapped operation is enqueued.

The number of bytes written will be returned as part of the completion notification when the I/O finishes.

Safety

This function is unsafe because the kernel requires that the buf and overlapped pointers are valid until the end of the I/O operation. The kernel also requires that overlapped is unique for this I/O operation and is not in use for any other I/O.

To safely use this function callers must ensure that these two input pointers are valid until the I/O operation is completed, typically via completion ports and waiting to receive the completion notification on the port.

source

unsafe fn connect_overlapped( &self, addr: &SocketAddr, buf: &[u8], overlapped: *mut OVERLAPPED ) -> Result<Option<usize>>

Attempt to consume the internal socket in this builder by executing an overlapped connect operation.

This function will issue a connect operation to the address specified on the underlying socket, flagging it as an overlapped operation which will complete asynchronously. If successful this function will return the corresponding Unix domain socket stream.

The buf argument provided is an initial buffer of data that should be sent after the connection is initiated. It’s acceptable to pass an empty slice here.

This function will also return whether the connect immediately succeeded or not. If Ok(None) is returned then the I/O operation is still pending and will complete later. If Ok(Some(bytes)) is returned then that many bytes were transferred.

Note that to succeed this requires that the underlying socket has previously been bound via a call to bind to a local path.

Safety

This function is unsafe because the kernel requires that the overlapped and buf pointers to be valid until the end of the I/O operation. The kernel also requires that overlapped is unique for this I/O operation and is not in use for any other I/O.

To safely use this function callers must ensure that this pointer is valid until the I/O operation is completed, typically via completion ports and waiting to receive the completion notification on the port.

source

fn connect_complete(&self) -> Result<()>

Once a connect_overlapped has finished, this function needs to be called to finish the connect operation.

Currently this just calls setsockopt with SO_UPDATE_CONNECT_CONTEXT to ensure that further functions like getpeername and getsockname work correctly.

source

unsafe fn result(&self, overlapped: *mut OVERLAPPED) -> Result<(usize, u32)>

Calls the GetOverlappedResult function to get the result of an overlapped operation for this handle.

This function takes the OVERLAPPED argument which must have been used to initiate an overlapped I/O operation, and returns either the successful number of bytes transferred during the operation or an error if one occurred, along with the results of the lpFlags parameter of the relevant operation, if applicable.

Safety

This function is unsafe as overlapped must have previously been used to execute an operation for this handle, and it must also be a valid pointer to an OVERLAPPED instance.

Panics

This function will panic

Implementors§