wasmer_wasix/syscalls/wasix/
sock_get_opt_size.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `sock_get_opt_size()`
5/// Retrieve the size of particular option for this socket
6/// Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF
7///
8/// ## Parameters
9///
10/// * `fd` - Socket descriptor
11/// * `sockopt` - Socket option to be retrieved
12#[instrument(level = "trace", skip_all, fields(%sock, %opt), ret)]
13pub fn sock_get_opt_size<M: MemorySize>(
14    mut ctx: FunctionEnvMut<'_, WasiEnv>,
15    sock: WasiFd,
16    opt: Sockoption,
17    ret_size: WasmPtr<Filesize, M>,
18) -> Errno {
19    let size = wasi_try!(__sock_actor(
20        &mut ctx,
21        sock,
22        Rights::empty(),
23        |socket, _| match opt {
24            Sockoption::RecvBufSize => socket.recv_buf_size().map(|a| a as Filesize),
25            Sockoption::SendBufSize => socket.send_buf_size().map(|a| a as Filesize),
26            Sockoption::Ttl => socket.ttl().map(|a| a as Filesize),
27            Sockoption::MulticastTtlV4 => {
28                socket.multicast_ttl_v4().map(|a| a as Filesize)
29            }
30            _ => Err(Errno::Inval),
31        }
32    ));
33
34    let env = ctx.data();
35    let memory = unsafe { env.memory_view(&ctx) };
36    wasi_try_mem!(ret_size.write(&memory, size));
37
38    Errno::Success
39}