1
1
#[ cfg( feature = "allocator_api" ) ]
2
2
use std:: alloc:: Allocator ;
3
3
4
- use compio_buf:: { buf_try , vec_alloc, BufResult , IntoInner , IoBuf , IoBufMut , IoVectoredBufMut } ;
4
+ use compio_buf:: { vec_alloc, BufResult , IntoInner , IoBuf , IoBufMut , IoVectoredBufMut } ;
5
5
6
6
use crate :: { util:: Take , AsyncRead , AsyncReadAt , IoResult } ;
7
7
@@ -41,20 +41,25 @@ macro_rules! loop_read_exact {
41
41
let len = $len;
42
42
43
43
while $tracker < len {
44
- ( $tracker, $buf) = buf_try!( $read_expr. await . into_inner( ) . and_then( |n, b| {
45
- if n == 0 {
46
- use :: std:: io:: { Error , ErrorKind } ;
47
- (
48
- Err ( Error :: new(
49
- ErrorKind :: UnexpectedEof ,
44
+ match $read_expr. await . into_inner( ) {
45
+ BufResult ( Ok ( 0 ) , buf) => {
46
+ return BufResult (
47
+ Err ( :: std:: io:: Error :: new(
48
+ :: std:: io:: ErrorKind :: UnexpectedEof ,
50
49
"failed to fill whole buffer" ,
51
50
) ) ,
52
- b,
53
- )
54
- } else {
55
- ( Ok ( $tracker + n) , b)
51
+ buf,
52
+ ) ;
56
53
}
57
- } ) ) ;
54
+ BufResult ( Ok ( n) , buf) => {
55
+ $tracker += n;
56
+ $buf = buf;
57
+ }
58
+ BufResult ( Err ( ref e) , buf) if e. kind( ) == :: std:: io:: ErrorKind :: Interrupted => {
59
+ $buf = buf;
60
+ }
61
+ res => return res,
62
+ }
58
63
}
59
64
return BufResult ( Ok ( $tracker) , $buf)
60
65
} ;
@@ -114,16 +119,23 @@ macro_rules! loop_read_vectored {
114
119
macro_rules! loop_read_to_end {
115
120
( $buf: ident, $tracker: ident : $tracker_ty: ty, loop $read_expr: expr) => { {
116
121
let mut $tracker: $tracker_ty = 0 ;
117
- let mut read;
118
122
loop {
119
123
if $buf. len( ) == $buf. capacity( ) {
120
124
$buf. reserve( 32 ) ;
121
125
}
122
- ( read, $buf) = buf_try!( $read_expr. await . into_inner( ) ) ;
123
- if read == 0 {
124
- break ;
125
- } else {
126
- $tracker += read as $tracker_ty;
126
+ match $read_expr. await . into_inner( ) {
127
+ BufResult ( Ok ( 0 ) , buf) => {
128
+ $buf = buf;
129
+ break ;
130
+ }
131
+ BufResult ( Ok ( read) , buf) => {
132
+ $tracker += read as $tracker_ty;
133
+ $buf = buf;
134
+ }
135
+ BufResult ( Err ( ref e) , buf) if e. kind( ) == :: std:: io:: ErrorKind :: Interrupted => {
136
+ $buf = buf
137
+ }
138
+ res => return res,
127
139
}
128
140
}
129
141
BufResult ( Ok ( $tracker as usize ) , $buf)
@@ -147,7 +159,7 @@ pub trait AsyncReadExt: AsyncRead {
147
159
148
160
/// Read the exact number of bytes required to fill the buf.
149
161
async fn read_exact < T : IoBufMut > ( & mut self , mut buf : T ) -> BufResult < usize , T > {
150
- loop_read_exact ! ( buf, buf. buf_capacity( ) - buf . buf_len ( ) , read, loop self . read( buf. slice( read..) ) ) ;
162
+ loop_read_exact ! ( buf, buf. buf_capacity( ) , read, loop self . read( buf. slice( read..) ) ) ;
151
163
}
152
164
153
165
/// Read all bytes until underlying reader reaches `EOF`.
@@ -221,7 +233,7 @@ pub trait AsyncReadAtExt: AsyncReadAt {
221
233
async fn read_exact_at < T : IoBufMut > ( & self , mut buf : T , pos : u64 ) -> BufResult < usize , T > {
222
234
loop_read_exact ! (
223
235
buf,
224
- buf. buf_capacity( ) - buf . buf_len ( ) ,
236
+ buf. buf_capacity( ) ,
225
237
read,
226
238
loop self . read_at( buf. slice( read..) , pos + read as u64 )
227
239
) ;
0 commit comments