Documentation
WASIX
sock_recv_from

sock_recv_from()

Receive a message and its peer address from a socket.

Description

The sock_recv_from() function is used to receive a message and its peer address from a socket. It is similar to the recvfrom function in POSIX, but it also supports reading the data into multiple buffers in the manner of readv.

The function receives data from the socket and stores it in the provided scatter/gather vectors. It also retrieves the peer address from which the message was received. The number of bytes stored in ri_data, the message flags, and the peer address are returned.

Syntax

  ;;; the data into multiple buffers in the manner of `readv`.
  ;;; Note: This is similar to `recvfrom` in POSIX, though it also supports reading
  ;;; Receive a message and its peer address from a socket.
  (@interface func (export "sock_recv_from")
    (param $fd $fd)
    ;;; List of scatter/gather vectors to which to store data.
    (param $ri_data $iovec_array)
    ;;; Message flags.
    (param $ri_flags $riflags)
    ;;; Number of bytes stored in ri_data and message flags.
    (result $error (expected (tuple $size $roflags $addr_port) (error $errno)))
  )

Parameters

  • ctx: A mutable reference to the function environment.
  • sock: The file descriptor of the socket to receive from.
  • ri_data: A list of scatter/gather vectors to which the received data will be stored.
  • ri_data_len: The length of the scatter/gather vector list.
  • _ri_flags: Message flags.
  • ro_data_len: A pointer to store the number of bytes read.
  • ro_flags: A pointer to store the message flags.
  • ro_addr: A pointer to store the peer address.

Return Value

The function returns a Result containing an Errno value. If the operation is successful, Errno::Success is returned. Otherwise, an appropriate Errno value indicating the error is returned.

Notes

  • The sock_recv_from() function receives a message from a socket and stores it in the provided scatter/gather vectors.
  • The function supports reading the data into multiple buffers.
  • The ri_data parameter represents a list of scatter/gather vectors, where each vector contains a buffer and its length.
  • The ri_data_len parameter specifies the length of the scatter/gather vector list.
  • The received data is stored in the buffers specified by the scatter/gather vectors.
  • The number of bytes read from the socket is stored in ro_data_len.
  • The message flags are stored in ro_flags.
  • The peer address from which the message was received is stored in ro_addr.
  • The specific behavior of the sock_recv_from() function may vary depending on the runtime environment and underlying networking implementation.