Add timeout send/recv and multicast client/server socket examples (#1519)

Add a couple of socket examples that can be used with WAMR:
- The `timeout_client` and `timeout_server` examples demonstrate socket
  send and receive timeouts using the socket options
- The `multicast_client` and `multicast_server` examples demonstrate receiving
  multicast packets in WASM

And add several macro controls for `socket_opts` example.
This commit is contained in:
Callum Macmillan
2022-10-07 03:31:21 +01:00
committed by GitHub
parent e2a3f0f387
commit 5ddc335a7f
9 changed files with 534 additions and 39 deletions

View File

@ -692,12 +692,12 @@ get_ipproto_ip_option(int sockfd, int optname, void *__restrict optval,
HANDLE_ERROR(error);
return error;
case IP_TTL:
assert(*optlen == sizeof(uint8_t));
assert(*optlen == sizeof(int));
error = __wasi_sock_get_ip_ttl(sockfd, (uint8_t *)optval);
HANDLE_ERROR(error);
return error;
case IP_MULTICAST_TTL:
assert(*optlen == sizeof(uint8_t));
assert(*optlen == sizeof(int));
error = __wasi_sock_get_ip_multicast_ttl(sockfd, (uint8_t *)optval);
HANDLE_ERROR(error);
return error;
@ -915,12 +915,12 @@ set_ipproto_ip_option(int sockfd, int optname, const void *optval,
HANDLE_ERROR(error);
return error;
case IP_TTL:
assert(optlen == sizeof(uint8_t));
assert(optlen == sizeof(int));
error = __wasi_sock_set_ip_ttl(sockfd, *(uint8_t *)optval);
HANDLE_ERROR(error);
return error;
case IP_MULTICAST_TTL:
assert(optlen == sizeof(uint8_t));
assert(optlen == sizeof(int));
error =
__wasi_sock_set_ip_multicast_ttl(sockfd, *(uint8_t *)optval);
HANDLE_ERROR(error);