Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ int uv__socket(int domain, int type, int protocol) {
int sockfd;
int err;

#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) && !defined(__wasi__) && !defined(__wasm32__)
sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
if (sockfd != -1)
return sockfd;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (delay < 1)
return UV_EINVAL;

#if defined(__wasi__) || defined(__wasm32__)
return 0;
#endif

#ifdef __sun
/* The implementation of TCP keep-alive on Solaris/SmartOS is a bit unusual
* compared to other Unix-like systems.
Expand Down
38 changes: 38 additions & 0 deletions src/unix/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ int uv__udp_connect(uv_udp_t* handle,
* if (addr->sa_family == AF_UNSPEC) sodisconnect(so);
*/
int uv__udp_disconnect(uv_udp_t* handle) {
#if defined(__wasi__)
handle->flags &= ~UV_HANDLE_UDP_CONNECTED;
return 0;
#else
int r;
#if defined(__MVS__)
struct sockaddr_storage addr;
Expand Down Expand Up @@ -570,6 +574,7 @@ int uv__udp_disconnect(uv_udp_t* handle) {

handle->flags &= ~UV_HANDLE_UDP_CONNECTED;
return 0;
#endif
}

int uv__udp_send(uv_udp_send_t* req,
Expand Down Expand Up @@ -1087,6 +1092,15 @@ int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {


int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
if (ttl < 1 || ttl > 255)
return UV_EINVAL;
if (handle->io_watcher.fd == -1)
return UV_EBADF;

#if defined(__wasi__)
return 0;
#endif

/*
* On Solaris and derivatives such as SmartOS, the length of socket options
* is sizeof(int) for IPV6_MULTICAST_HOPS and sizeof(char) for
Expand All @@ -1112,6 +1126,13 @@ int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {


int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
if (handle->io_watcher.fd == -1)
return UV_EBADF;

#if defined(__wasi__)
return 0;
#endif

/*
* On Solaris and derivatives such as SmartOS, the length of socket options
* is sizeof(int) for IPV6_MULTICAST_LOOP and sizeof(char) for
Expand Down Expand Up @@ -1140,6 +1161,9 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
struct sockaddr_in* addr4;
struct sockaddr_in6* addr6;

if (handle->io_watcher.fd == -1)
return UV_EBADF;

addr4 = (struct sockaddr_in*) &addr_st;
addr6 = (struct sockaddr_in6*) &addr_st;

Expand All @@ -1160,6 +1184,20 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
return UV_EINVAL;
}

#if defined(__wasi__)
if ((handle->flags & UV_HANDLE_IPV6) && addr_st.ss_family == AF_INET)
return UV_EINVAL;
if (!(handle->flags & UV_HANDLE_IPV6) && addr_st.ss_family == AF_INET6)
return UV_EINVAL;
if (addr_st.ss_family == AF_INET &&
IN_MULTICAST(ntohl(addr4->sin_addr.s_addr))) {
return UV_EINVAL;
}
if (addr_st.ss_family == AF_INET6 && IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr))
return UV_EINVAL;
return 0;
#endif

if (addr_st.ss_family == AF_INET) {
if (setsockopt(handle->io_watcher.fd,
IPPROTO_IP,
Expand Down
5 changes: 5 additions & 0 deletions src/uv-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr) {


int uv__udp_is_connected(uv_udp_t* handle) {
#if defined(__wasi__)
return handle->type == UV_UDP &&
(handle->flags & UV_HANDLE_UDP_CONNECTED) != 0;
#else
struct sockaddr_storage addr;
int addrlen;
if (handle->type != UV_UDP)
Expand All @@ -453,6 +457,7 @@ int uv__udp_is_connected(uv_udp_t* handle) {
return 0;

return addrlen > 0;
#endif
}


Expand Down