pub trait HostOutgoingDatagramStream: Send {
// Required methods
fn check_send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<u64, SocketError>;
fn send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
datagrams: Vec<OutgoingDatagram>,
) -> impl Future<Output = Result<u64, SocketError>> + Send;
fn subscribe(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<Resource<Pollable>>;
fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> Result<()>;
}
Required Methods§
Sourcefn check_send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<u64, SocketError>
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
.
Sourcefn send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
datagrams: Vec<OutgoingDatagram>,
) -> impl Future<Output = Result<u64, SocketError>> + Send
fn send( &mut self, self_: Resource<OutgoingDatagramStream>, datagrams: Vec<OutgoingDatagram>, ) -> impl Future<Output = Result<u64, SocketError>> + Send
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
: Theremote-address
has the wrong address family. (EAFNOSUPPORT)invalid-argument
: The IP address inremote-address
is set to INADDR_ANY (0.0.0.0
/::
). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument
: The port inremote-address
is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument
: The socket is in “connected” mode andremote-address
issome
value that does not match the address passed tostream
. (EISCONN)invalid-argument
: The socket is not “connected” and no value forremote-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
- https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html
- https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html
- https://man7.org/linux/man-pages/man2/send.2.html
- https://man7.org/linux/man-pages/man2/sendmmsg.2.html
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg
- https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2
Sourcefn subscribe(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<Resource<Pollable>>
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.
fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> Result<()>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<_T: HostOutgoingDatagramStream + ?Sized + Send> HostOutgoingDatagramStream for &mut _T
impl<_T: HostOutgoingDatagramStream + ?Sized + Send> HostOutgoingDatagramStream for &mut _T
Source§fn check_send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<u64, SocketError>
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§async fn send(
&mut self,
self_: Resource<OutgoingDatagramStream>,
datagrams: Vec<OutgoingDatagram>,
) -> Result<u64, SocketError>
async fn send( &mut self, self_: Resource<OutgoingDatagramStream>, datagrams: Vec<OutgoingDatagram>, ) -> Result<u64, SocketError>
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
: Theremote-address
has the wrong address family. (EAFNOSUPPORT)invalid-argument
: The IP address inremote-address
is set to INADDR_ANY (0.0.0.0
/::
). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument
: The port inremote-address
is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument
: The socket is in “connected” mode andremote-address
issome
value that does not match the address passed tostream
. (EISCONN)invalid-argument
: The socket is not “connected” and no value forremote-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
- https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html
- https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html
- https://man7.org/linux/man-pages/man2/send.2.html
- https://man7.org/linux/man-pages/man2/sendmmsg.2.html
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
- https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg
- https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2
Source§fn subscribe(
&mut self,
self_: Resource<OutgoingDatagramStream>,
) -> Result<Resource<Pollable>>
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.