Skip to content
Merged
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
4 changes: 2 additions & 2 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NS_PER_S
_CLOCK_MONOTONIC
_CLOCK_REALTIME
_Exit
Expand Down Expand Up @@ -343,6 +342,8 @@ __wasilibc_rmdirat
__wasilibc_sockaddr_to_wasi
__wasilibc_sockaddr_validate
__wasilibc_stat
__wasilibc_tcp_getsockopt
__wasilibc_tcp_setsockopt
__wasilibc_tell
__wasilibc_unlinkat
__wasilibc_unspecified_addr
Expand Down Expand Up @@ -1384,7 +1385,6 @@ tcp_result_u32_error_code_free
tcp_result_u64_error_code_free
tcp_result_u8_error_code_free
tcp_result_void_error_code_free
tcp_setsockopt
tcp_tcp_socket_drop_own
tdelete
tdestroy
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip3/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ __wasilibc_rmdirat
__wasilibc_sockaddr_to_wasi
__wasilibc_sockaddr_validate
__wasilibc_stat
__wasilibc_tcp_getsockopt
__wasilibc_tcp_setsockopt
__wasilibc_tell
__wasilibc_unlinkat
__wasilibc_unspecified_addr
Expand Down
1 change: 1 addition & 0 deletions libc-bottom-half/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ else()
sources/socket.c
sources/sockets_utils.c
sources/sockopt.c
sources/tcp_sockopt.c
)
endif()

Expand Down
80 changes: 80 additions & 0 deletions libc-bottom-half/headers/private/wasi/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,86 @@
#ifndef __wasip1__

#include <wasi/sockets_utils.h>
#include <sys/socket.h>

// Normalize names on WASIp2 to the WASIp3-based names
#ifdef __wasip2__
typedef network_error_code_t sockets_error_code_t;
typedef tcp_own_tcp_socket_t sockets_own_tcp_socket_t;
typedef tcp_borrow_tcp_socket_t sockets_borrow_tcp_socket_t;
typedef network_ip_address_family_t sockets_ip_address_family_t;
#define sockets_borrow_tcp_socket tcp_borrow_tcp_socket
#endif // __wasip2__

typedef struct {
int dummy;
} tcp_socket_state_unbound_t;
typedef struct {
int dummy;
} tcp_socket_state_bound_t;
typedef struct {
int dummy;
} tcp_socket_state_connecting_t;
typedef struct {
int dummy;
} tcp_socket_state_listening_t;

// Pollables here are lazily initialized on-demand.
typedef struct {
#ifdef __wasip2__
streams_own_input_stream_t input;
poll_own_pollable_t input_pollable;
streams_own_output_stream_t output;
poll_own_pollable_t output_pollable;
#else
int dummy; // TODO(wasip3)
#endif
} tcp_socket_state_connected_t;

typedef struct {
sockets_error_code_t error_code;
} tcp_socket_state_connect_failed_t;

// This is a tagged union. When adding/removing/renaming cases, be sure to keep
// the tag and union definitions in sync.
typedef struct {
enum {
TCP_SOCKET_STATE_UNBOUND,
TCP_SOCKET_STATE_BOUND,
TCP_SOCKET_STATE_CONNECTING,
TCP_SOCKET_STATE_CONNECTED,
TCP_SOCKET_STATE_CONNECT_FAILED,
TCP_SOCKET_STATE_LISTENING,
} tag;
union {
tcp_socket_state_unbound_t unbound;
tcp_socket_state_bound_t bound;
tcp_socket_state_connecting_t connecting;
tcp_socket_state_connected_t connected;
tcp_socket_state_connect_failed_t connect_failed;
tcp_socket_state_listening_t listening;
};
} tcp_socket_state_t;

typedef struct {
sockets_own_tcp_socket_t socket;
tcp_socket_state_t state;
#ifdef __wasip2__
// This pollable is lazily initialized on-demand.
poll_own_pollable_t socket_pollable;
#endif
bool blocking;
bool fake_nodelay;
bool fake_reuseaddr;
sockets_ip_address_family_t family;
monotonic_clock_duration_t send_timeout;
monotonic_clock_duration_t recv_timeout;
} tcp_socket_t;

int __wasilibc_tcp_getsockopt(void *data, int level, int optname,
void *restrict optval, socklen_t *restrict optlen);
int __wasilibc_tcp_setsockopt(void *data, int level, int optname,
const void *optval, socklen_t optlen);

/// Adds the provided TCP socket to the descriptor table, returning the
/// corresponding file descriptor.
Expand Down
Loading