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