wasmtime_wasi::bindings::sockets::udp

Trait HostOutgoingDatagramStream

Source
pub trait HostOutgoingDatagramStream {
    // Required methods
    fn check_send(
        &mut self,
        self_: Resource<OutgoingDatagramStream>,
    ) -> Result<u64, SocketError>;
    fn send<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutgoingDatagramStream>,
        datagrams: Vec<OutgoingDatagram>,
    ) -> Pin<Box<dyn Future<Output = Result<u64, SocketError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn subscribe(
        &mut self,
        self_: Resource<OutgoingDatagramStream>,
    ) -> Result<Resource<Pollable>>;
    fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> Result<()>;
}

Required Methods§

Source

fn check_send( &mut self, self_: Resource<OutgoingDatagramStream>, ) -> Result<u64, SocketError>

Check readiness for sending. This function never blocks.

Returns the number of datagrams permitted for the next call to send, or an error. Calling send with more datagrams than this function has permitted will trap.

When this function returns ok(0), the subscribe pollable will become ready when this function will report at least ok(1), or an error.

Never returns would-block.

Source

fn send<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutgoingDatagramStream>, datagrams: Vec<OutgoingDatagram>, ) -> Pin<Box<dyn Future<Output = Result<u64, SocketError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send messages on the socket.

This function attempts to send all provided datagrams on the socket without blocking and returns how many messages were actually sent (or queued for sending). This function never returns error(would-block). If none of the datagrams were able to be sent, ok(0) is returned.

This function semantically behaves the same as iterating the datagrams list and sequentially sending each individual datagram until either the end of the list has been reached or the first error occurred. If at least one datagram has been sent successfully, this function never returns an error.

If the input list is empty, the function returns ok(0).

Each call to send must be permitted by a preceding check-send. Implementations must trap if either check-send was not called or datagrams contains more items than check-send permitted.

§Typical errors
  • invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)
  • invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)
  • invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
  • invalid-argument: The socket is in “connected” mode and remote-address is some value that does not match the address passed to stream. (EISCONN)
  • invalid-argument: The socket is not “connected” and no value for remote-address was provided. (EDESTADDRREQ)
  • remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
  • connection-refused: The connection was refused. (ECONNREFUSED)
  • datagram-too-large: The datagram is too large. (EMSGSIZE)
§References
Source

fn subscribe( &mut self, self_: Resource<OutgoingDatagramStream>, ) -> Result<Resource<Pollable>>

Create a pollable which will resolve once the stream is ready to send again.

Note: this function is here for WASI 0.2 only. It’s planned to be removed when future is natively supported in Preview3.

Source

fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> Result<()>

Implementations on Foreign Types§

Source§

impl<_T: HostOutgoingDatagramStream + ?Sized + Send> HostOutgoingDatagramStream for &mut _T

Source§

fn check_send( &mut self, self_: Resource<OutgoingDatagramStream>, ) -> Result<u64, SocketError>

Check readiness for sending. This function never blocks.

Returns the number of datagrams permitted for the next call to send, or an error. Calling send with more datagrams than this function has permitted will trap.

When this function returns ok(0), the subscribe pollable will become ready when this function will report at least ok(1), or an error.

Never returns would-block.

Source§

fn send<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutgoingDatagramStream>, datagrams: Vec<OutgoingDatagram>, ) -> Pin<Box<dyn Future<Output = Result<u64, SocketError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send messages on the socket.

This function attempts to send all provided datagrams on the socket without blocking and returns how many messages were actually sent (or queued for sending). This function never returns error(would-block). If none of the datagrams were able to be sent, ok(0) is returned.

This function semantically behaves the same as iterating the datagrams list and sequentially sending each individual datagram until either the end of the list has been reached or the first error occurred. If at least one datagram has been sent successfully, this function never returns an error.

If the input list is empty, the function returns ok(0).

Each call to send must be permitted by a preceding check-send. Implementations must trap if either check-send was not called or datagrams contains more items than check-send permitted.

§Typical errors
  • invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)
  • invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)
  • invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
  • invalid-argument: The socket is in “connected” mode and remote-address is some value that does not match the address passed to stream. (EISCONN)
  • invalid-argument: The socket is not “connected” and no value for remote-address was provided. (EDESTADDRREQ)
  • remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
  • connection-refused: The connection was refused. (ECONNREFUSED)
  • datagram-too-large: The datagram is too large. (EMSGSIZE)
§References
Source§

fn subscribe( &mut self, self_: Resource<OutgoingDatagramStream>, ) -> Result<Resource<Pollable>>

Create a pollable which will resolve once the stream is ready to send again.

Note: this function is here for WASI 0.2 only. It’s planned to be removed when future is natively supported in Preview3.

Source§

fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> Result<()>

Implementors§