Skip to content

Commit e8438cc

Browse files
alexcrichtoncpetig
andauthored
wasip3: Fill out more of the TCP implementation (WebAssembly#761)
Remaining test failures and future work items are: * Nonblocking reads/writes/accepts/connects/etc * Timed-out reads/writes --------- Co-authored-by: Christof Petig <christof.petig@arcor.de>
1 parent 65ad12f commit e8438cc

8 files changed

Lines changed: 291 additions & 59 deletions

File tree

libc-bottom-half/headers/private/wasi/tcp.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,25 @@ typedef struct {
2424
int dummy;
2525
} tcp_socket_state_bound_t;
2626
typedef struct {
27+
#ifdef __wasip2__
2728
int dummy;
29+
#else
30+
// Arguments, results, and subtask connected to `[method]tcp-socket.connect`
31+
// while it's in-progress. Note that `subtask` may be 0 in which case it means
32+
// that `result` is valid as it's been filled in.
33+
sockets_method_tcp_socket_connect_args_t args;
34+
sockets_result_void_error_code_t result;
35+
wasip3_subtask_t subtask;
36+
#endif
2837
} tcp_socket_state_connecting_t;
2938
typedef struct {
39+
#ifdef __wasip2__
3040
int dummy;
41+
#else
42+
// The `stream<tcp-socket>` that this is reading to receive accepted sockets.
43+
sockets_stream_own_tcp_socket_t stream;
44+
bool done;
45+
#endif
3146
} tcp_socket_state_listening_t;
3247

3348
// Pollables here are lazily initialized on-demand.
@@ -38,7 +53,19 @@ typedef struct {
3853
streams_own_output_stream_t output;
3954
poll_own_pollable_t output_pollable;
4055
#else
41-
int dummy; // TODO(wasip3)
56+
// The bytes that are being received on this socket in addition to the future
57+
// of the result to read when the socket hits EOF to see if there's an error.
58+
sockets_stream_u8_t receive;
59+
sockets_future_result_void_error_code_t receive_result;
60+
61+
// The stream to write to in order to send out bytes, along with the `send`
62+
// subtask that was created connected to the other half of `send`. The
63+
// result of the subtask at `send_result` will get filled in when
64+
// `send_subtask` is finished.
65+
sockets_stream_u8_writer_t send;
66+
wasip3_subtask_t send_subtask;
67+
sockets_result_void_error_code_t send_result;
68+
bool send_done;
4269
#endif
4370
} tcp_socket_state_connected_t;
4471

libc-bottom-half/sources/file_utils.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// TODO(wasip3) these are load-bearing assertions functionality-wise, but once
2+
// the assertions below are removed and the implementation is filled in then
3+
// this should be removed.
4+
#undef NDEBUG
5+
16
#include <assert.h>
27
#include <common/errors.h>
38
#include <errno.h>

0 commit comments

Comments
 (0)