]>
Commit | Line | Data |
---|---|---|
320054e8 DG |
1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ |
2 | // | |
3 | // SPDX-License-Identifier: BSD-2-Clause | |
4 | ||
5 | #include <common/errno.h> | |
6 | ||
7 | #include <sys/socket.h> | |
8 | ||
9 | #include <assert.h> | |
446cb3f1 | 10 | #include <wasi/api.h> |
320054e8 DG |
11 | #include <errno.h> |
12 | ||
13 | ssize_t send(int socket, const void *buffer, size_t length, int flags) { | |
14 | // This implementation does not support any flags. | |
15 | if (flags != 0) { | |
16 | errno = EOPNOTSUPP; | |
17 | return -1; | |
18 | } | |
19 | ||
20 | // Prepare input parameters. | |
21 | __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; | |
320054e8 DG |
22 | __wasi_ciovec_t *si_data = &iov; |
23 | size_t si_data_len = 1; | |
24 | __wasi_siflags_t si_flags = 0; | |
320054e8 DG |
25 | |
26 | // Perform system call. | |
320054e8 DG |
27 | size_t so_datalen; |
28 | __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); | |
320054e8 DG |
29 | if (error != 0) { |
30 | errno = errno_fixup_socket(socket, error); | |
31 | return -1; | |
32 | } | |
320054e8 | 33 | return so_datalen; |
320054e8 | 34 | } |