forked from WebAssembly/wasi-libc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement basic TCP/UDP client support (WebAssembly#477)
* implement basic TCP/UDP client support This implements `socket`, `connect`, `recv`, `send`, etc. in terms of `wasi-sockets` for the `wasm32-wasip2` target. I've introduced a new public header file: `__wasi_snapshot.h`, which will define a preprocessor symbol `__wasilibc_use_wasip2` if using the `wasm32-wasip2` version of the header, in which case we provide features only available for that target. Co-authored-by: Dave Bakker <[email protected]> Signed-off-by: Joel Dice <[email protected]> * fix grammar in __wasi_snapshot.h comment Co-authored-by: Dan Gohman <[email protected]> Signed-off-by: Joel Dice <[email protected]> --------- Signed-off-by: Joel Dice <[email protected]> Co-authored-by: Dave Bakker <[email protected]> Co-authored-by: Dan Gohman <[email protected]>
- Loading branch information
1 parent
a963040
commit 684f155
Showing
17 changed files
with
1,377 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef __wasi_sockets_utils_h | ||
#define __wasi_sockets_utils_h | ||
|
||
#include <netinet/in.h> | ||
|
||
#include <wasi/descriptor_table.h> | ||
|
||
typedef struct { | ||
enum { | ||
OUTPUT_SOCKADDR_NULL, | ||
OUTPUT_SOCKADDR_V4, | ||
OUTPUT_SOCKADDR_V6, | ||
} tag; | ||
union { | ||
struct { | ||
int dummy; | ||
} null; | ||
struct { | ||
struct sockaddr_in *addr; | ||
socklen_t *addrlen; | ||
} v4; | ||
struct { | ||
struct sockaddr_in6 *addr; | ||
socklen_t *addrlen; | ||
} v6; | ||
}; | ||
} output_sockaddr_t; | ||
|
||
network_borrow_network_t __wasi_sockets_utils__borrow_network(); | ||
int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); | ||
bool __wasi_sockets_utils__parse_address( | ||
network_ip_address_family_t expected_family, | ||
const struct sockaddr *address, socklen_t len, | ||
network_ip_socket_address_t *result, int *error); | ||
bool __wasi_sockets_utils__output_addr_validate( | ||
network_ip_address_family_t expected_family, struct sockaddr *addr, | ||
socklen_t *addrlen, output_sockaddr_t *result); | ||
void __wasi_sockets_utils__output_addr_write( | ||
const network_ip_socket_address_t input, output_sockaddr_t *output); | ||
int __wasi_sockets_utils__posix_family(network_ip_address_family_t wasi_family); | ||
network_ip_socket_address_t | ||
__wasi_sockets_utils__any_addr(network_ip_address_family_t family); | ||
int __wasi_sockets_utils__tcp_bind(tcp_socket_t *socket, | ||
network_ip_socket_address_t *address); | ||
int __wasi_sockets_utils__udp_bind(udp_socket_t *socket, | ||
network_ip_socket_address_t *address); | ||
bool __wasi_sockets_utils__stream(udp_socket_t *socket, | ||
network_ip_socket_address_t *remote_address, | ||
udp_socket_streams_t *result, | ||
network_error_code_t *error); | ||
void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* This file is (practically) empty by default. The Makefile will replace it | ||
with a non-empty version that defines `__wasilibc_use_wasip2` if targeting | ||
`wasm32-wasip2`. | ||
*/ | ||
|
Oops, something went wrong.