@@ -40,7 +40,12 @@ impl AsyncRead for AsyncInputStream {
40
40
// Ideally, the ABI would be able to read directly into buf. However, with the default
41
41
// generated bindings, it returns a newly allocated vec, which we need to copy into buf.
42
42
let read = match self . stream . read ( buf. len ( ) as u64 ) {
43
+ // We don't need to special-case 0 here: a value of 0 bytes from
44
+ // WASI's `read` doesn't mean end-of-stream as it does in Rust,
45
+ // however since we called `self.ready()`, we'll always get at
46
+ // least one byte.
43
47
Ok ( r) => r,
48
+ // 0 bytes from Rust's `read` means end-of-stream.
44
49
Err ( StreamError :: Closed ) => return Ok ( 0 ) ,
45
50
Err ( StreamError :: LastOperationFailed ( err) ) => {
46
51
return Err ( std:: io:: Error :: other ( err. to_debug_string ( ) ) )
@@ -97,13 +102,17 @@ impl AsyncWrite for AsyncOutputStream {
97
102
let writable = some. try_into ( ) . unwrap_or ( usize:: MAX ) . min ( buf. len ( ) ) ;
98
103
match self . stream . write ( & buf[ 0 ..writable] ) {
99
104
Ok ( ( ) ) => return Ok ( writable) ,
100
- Err ( StreamError :: Closed ) => return Ok ( 0 ) ,
105
+ Err ( StreamError :: Closed ) => {
106
+ return Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: ConnectionReset ) )
107
+ }
101
108
Err ( StreamError :: LastOperationFailed ( err) ) => {
102
109
return Err ( std:: io:: Error :: other ( err. to_debug_string ( ) ) )
103
110
}
104
111
}
105
112
}
106
- Err ( StreamError :: Closed ) => return Ok ( 0 ) ,
113
+ Err ( StreamError :: Closed ) => {
114
+ return Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: ConnectionReset ) )
115
+ }
107
116
Err ( StreamError :: LastOperationFailed ( err) ) => {
108
117
return Err ( std:: io:: Error :: other ( err. to_debug_string ( ) ) )
109
118
}
@@ -116,7 +125,9 @@ impl AsyncWrite for AsyncOutputStream {
116
125
self . ready ( ) . await ;
117
126
Ok ( ( ) )
118
127
}
119
- Err ( StreamError :: Closed ) => Ok ( ( ) ) ,
128
+ Err ( StreamError :: Closed ) => {
129
+ Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: ConnectionReset ) )
130
+ }
120
131
Err ( StreamError :: LastOperationFailed ( err) ) => {
121
132
Err ( std:: io:: Error :: other ( err. to_debug_string ( ) ) )
122
133
}
0 commit comments