88#include <sys/stat.h>
99#include <netinet/in.h>
1010
11- #ifdef __wasip2__
1211// Metadata for WASI reads which is used to delegate to `__wasilibc_read(...)`
1312// to perform the actual read of a stream.
14- typedef struct wasip2_read_t {
15- // The `wasi:io/streams.input-stream` that this is reading from.
16- streams_borrow_input_stream_t input ;
13+ typedef struct wasi_read_t {
1714 // An optional pointer to the internal offset of this stream, updated on
1815 // successful reads.
1916 off_t * offset ;
20- // A required pointer to an owned pollable for `input`. This is lazily
21- // initialized as-necessary.
22- poll_own_pollable_t * pollable ;
2317 // Whether or not this read will use blocking I/O.
2418 bool blocking ;
2519 // The timeout, in nanoseconds, for this operation.
2620 monotonic_clock_duration_t timeout ;
27- } wasip2_read_t ;
21+ #ifdef __wasip2__
22+ // The `wasi:io/streams.input-stream` that this is reading from.
23+ streams_borrow_input_stream_t input ;
24+ // A required pointer to an owned pollable for `input`. This is lazily
25+ // initialized as-necessary.
26+ poll_own_pollable_t * pollable ;
27+ #else
28+ // The `stream<u8>` that's being read.
29+ filesystem_stream_u8_t stream ;
30+
31+ // A callback/ptr pair to invoke when EOF is reached to set errno and return
32+ // an error code.
33+ int (* eof )(void * );
34+ void * eof_data ;
35+ #endif
36+ } wasi_read_t ;
2837
29- // Same as `wasip2_read_t`, but for writes.
30- typedef struct wasip2_write_t {
31- streams_borrow_output_stream_t output ;
38+ // Same as `wasip_read_t`, but for writes.
39+ typedef struct wasi_write_t {
3240 off_t * offset ;
33- poll_own_pollable_t * pollable ;
3441 bool blocking ;
3542 monotonic_clock_duration_t timeout ;
36- } wasip2_write_t ;
37- #endif
38-
39- #ifdef __wasip3__
40- // create an alias to distinguish the handle type in the API
41- typedef uint32_t waitable_t ;
4243
43- /**
44- * This data structure represents the write end of a file
45- */
46- typedef struct wasip3_write_t {
44+ #ifdef __wasip2__
45+ streams_borrow_output_stream_t output ;
46+ poll_own_pollable_t * pollable ;
47+ #else
4748 filesystem_stream_u8_writer_t output ;
4849 // contents will be filled by host (once write has an error)
4950 filesystem_result_void_error_code_t pending_result ;
5051 // this task gets ready on error or eof
51- wasip3_subtask_t subtask ;
52- } wasip3_write_t ;
52+ wasip3_subtask_t * subtask ;
53+ #endif
54+ } wasi_write_t ;
55+
56+ #ifdef __wasip3__
57+ // create an alias to distinguish the handle type in the API
58+ typedef uint32_t waitable_t ;
5359#endif
5460
5561/**
@@ -71,18 +77,12 @@ typedef struct descriptor_vtable_t {
7177 // =====================================================================
7278 // Generic I/O
7379
74- #ifdef __wasip2__
7580 /// Looks up metadata to perform a read operation for this stream. This is used
7681 /// to implement the `read` syscall, for example, and is also used with `poll`
7782 /// when waiting for readability.
78- int (* get_read_stream )(void * , wasip2_read_t * );
83+ int (* get_read_stream )(void * , wasi_read_t * );
7984 /// Same as `get_read_stream`, but for output streams.
80- int (* get_write_stream )(void * , wasip2_write_t * );
81- #endif
82- #ifdef __wasip3__
83- int (* get_read_stream3 )(void * , filesystem_tuple2_stream_u8_future_result_void_error_code_t * * out , off_t * * off );
84- int (* get_write_stream3 )(void * , wasip3_write_t * * write_end , off_t * * );
85- #endif
85+ int (* get_write_stream )(void * , wasi_write_t * );
8686
8787 /// Sets the nonblocking flag for this object to the specified value.
8888 int (* set_blocking )(void * , bool );
0 commit comments