Skip to content

Commit

Permalink
Add wasm32-wasip2 definitions necessary for socket2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrum committed Oct 16, 2024
1 parent 0a1eef9 commit 1300509
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libc-test/semver/wasi-p2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,59 @@ sockaddr_storage
addrinfo
ip_mreq
ipv6_mreq
linger
SHUT_RD
SHUT_WR
SHUT_RDWR
MSG_NOSIGNAL
MSG_PEEK
SO_REUSEADDR
SO_TYPE
SO_ERROR
SO_BROADCAST
SO_SNDBUF
SO_RCVBUF
SO_KEEPALIVE
SO_LINGER
SO_ACCEPTCONN
SO_PROTOCOL
SO_DOMAIN
SO_RCVTIMEO
SO_SNDTIMEO
SOCK_DGRAM
SOCK_STREAM
SOCK_NONBLOCK
SOL_SOCKET
AF_UNSPEC
AF_INET
AF_INET6
IPPROTO_IP
IPPROTO_TCP
IPPROTO_UDP
IPPROTO_IPV6
IP_TTL
IP_MULTICAST_TTL
IP_MULTICAST_LOOP
IP_ADD_MEMBERSHIP
IP_DROP_MEMBERSHIP
IPV6_UNICAST_HOPS
IPV6_MULTICAST_LOOP
IPV6_JOIN_GROUP
IPV6_LEAVE_GROUP
IPV6_V6ONLY
IPV6_ADD_MEMBERSHIP
IPV6_DROP_MEMBERSHIP
TCP_NODELAY
TCP_KEEPIDLE
TCP_KEEPINTVL
TCP_KEEPCNT
EAI_SYSTEM
socket
connect
bind
listen
accept
accept4
getsockname
getpeername
sendto
Expand Down
25 changes: 25 additions & 0 deletions src/wasi/p2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ s! {
pub ipv6mr_multiaddr: in6_addr,
pub ipv6mr_interface: ::c_uint,
}

pub struct linger {
pub l_onoff: ::c_int,
pub l_linger: ::c_int,
}
}

pub const SHUT_RD: ::c_int = 1 << 0;
Expand All @@ -72,22 +77,32 @@ pub const MSG_NOSIGNAL: ::c_int = 0x4000;
pub const MSG_PEEK: ::c_int = 0x0002;

pub const SO_REUSEADDR: ::c_int = 2;
pub const SO_TYPE: ::c_int = 3;
pub const SO_ERROR: ::c_int = 4;
pub const SO_BROADCAST: ::c_int = 6;
pub const SO_SNDBUF: ::c_int = 7;
pub const SO_RCVBUF: ::c_int = 8;
pub const SO_KEEPALIVE: ::c_int = 9;
pub const SO_LINGER: ::c_int = 13;
pub const SO_ACCEPTCONN: ::c_int = 30;
pub const SO_PROTOCOL: ::c_int = 38;
pub const SO_DOMAIN: ::c_int = 39;
pub const SO_RCVTIMEO: ::c_int = 66;
pub const SO_SNDTIMEO: ::c_int = 67;

pub const SOCK_DGRAM: ::c_int = 5;
pub const SOCK_STREAM: ::c_int = 6;
pub const SOCK_NONBLOCK: ::c_int = 0x00004000;

pub const SOL_SOCKET: ::c_int = 0x7fffffff;

pub const AF_UNSPEC: ::c_int = 0;
pub const AF_INET: ::c_int = 1;
pub const AF_INET6: ::c_int = 2;

pub const IPPROTO_IP: ::c_int = 0;
pub const IPPROTO_TCP: ::c_int = 6;
pub const IPPROTO_UDP: ::c_int = 17;
pub const IPPROTO_IPV6: ::c_int = 41;

pub const IP_TTL: ::c_int = 2;
Expand All @@ -96,6 +111,7 @@ pub const IP_MULTICAST_LOOP: ::c_int = 34;
pub const IP_ADD_MEMBERSHIP: ::c_int = 35;
pub const IP_DROP_MEMBERSHIP: ::c_int = 36;

pub const IPV6_UNICAST_HOPS: ::c_int = 16;
pub const IPV6_MULTICAST_LOOP: ::c_int = 19;
pub const IPV6_JOIN_GROUP: ::c_int = 20;
pub const IPV6_LEAVE_GROUP: ::c_int = 21;
Expand All @@ -105,6 +121,9 @@ pub const IPV6_ADD_MEMBERSHIP: ::c_int = IPV6_JOIN_GROUP;
pub const IPV6_DROP_MEMBERSHIP: ::c_int = IPV6_LEAVE_GROUP;

pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_KEEPIDLE: ::c_int = 4;
pub const TCP_KEEPINTVL: ::c_int = 5;
pub const TCP_KEEPCNT: ::c_int = 6;

pub const EAI_SYSTEM: ::c_int = -11;

Expand All @@ -114,6 +133,12 @@ extern "C" {
pub fn bind(socket: ::c_int, addr: *const sockaddr, addrlen: socklen_t) -> ::c_int;
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
pub fn accept(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
pub fn accept4(
socket: ::c_int,
addr: *mut sockaddr,
addrlen: *mut socklen_t,
flags: ::c_int,
) -> ::c_int;

pub fn getsockname(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
pub fn getpeername(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
Expand Down

0 comments on commit 1300509

Please sign in to comment.