Implement sock_send_to and sock_recv_from system calls (#1457)
This commit is contained in:
@ -126,6 +126,14 @@ recvmsg(int sockfd, struct msghdr *msg, int flags);
|
||||
ssize_t
|
||||
sendmsg(int sockfd, const struct msghdr *msg, int flags);
|
||||
|
||||
ssize_t
|
||||
sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
|
||||
ssize_t
|
||||
recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
struct sockaddr *src_addr, socklen_t *addrlen);
|
||||
|
||||
int
|
||||
socket(int domain, int type, int protocol);
|
||||
|
||||
@ -257,6 +265,48 @@ __wasi_sock_bind(__wasi_fd_t fd, __wasi_addr_t *addr)
|
||||
(int32_t)fd, (int32_t)addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data to a specific target
|
||||
* Note: This is similar to `sendto` in POSIX
|
||||
*/
|
||||
int32_t
|
||||
__imported_wasi_snapshot_preview1_sock_send_to(int32_t arg0, int32_t arg1,
|
||||
int32_t arg2, int32_t arg3,
|
||||
int32_t arg4, int32_t arg5)
|
||||
__attribute__((__import_module__("wasi_snapshot_preview1"),
|
||||
__import_name__("sock_send_to")));
|
||||
|
||||
static inline __wasi_errno_t
|
||||
__wasi_sock_send_to(__wasi_fd_t fd, const __wasi_ciovec_t *si_data,
|
||||
uint32_t si_data_len, __wasi_siflags_t si_flags,
|
||||
const __wasi_addr_t *dest_addr, uint32_t *so_data_len)
|
||||
{
|
||||
return (__wasi_errno_t)__imported_wasi_snapshot_preview1_sock_send_to(
|
||||
(int32_t)fd, (int32_t)si_data, (int32_t)si_data_len, (int32_t)si_flags,
|
||||
(uint32_t)dest_addr, (uint32_t)so_data_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives data from a socket
|
||||
* Note: This is similar to `recvfrom` in POSIX
|
||||
*/
|
||||
int32_t
|
||||
__imported_wasi_snapshot_preview1_sock_recv_from(int32_t arg0, int32_t arg1,
|
||||
int32_t arg2, int32_t arg3,
|
||||
int32_t arg4, int32_t arg5)
|
||||
__attribute__((__import_module__("wasi_snapshot_preview1"),
|
||||
__import_name__("sock_recv_from")));
|
||||
|
||||
static inline __wasi_errno_t
|
||||
__wasi_sock_recv_from(__wasi_fd_t fd, __wasi_ciovec_t *ri_data,
|
||||
uint32_t ri_data_len, __wasi_riflags_t ri_flags,
|
||||
__wasi_addr_t *src_addr, uint32_t *ro_data_len)
|
||||
{
|
||||
return (__wasi_errno_t)__imported_wasi_snapshot_preview1_sock_recv_from(
|
||||
(int32_t)fd, (int32_t)ri_data, (int32_t)ri_data_len, (int32_t)ri_flags,
|
||||
(uint32_t)src_addr, (uint32_t)ro_data_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a socket (this is an alias for `fd_close`)
|
||||
* Note: This is similar to `close` in POSIX.
|
||||
|
||||
Reference in New Issue
Block a user