File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change 1
- use crate :: future:: { Future , PollState } ;
1
+ use crate :: { future:: PollState , runtime, Future } ;
2
+ use mio:: { Interest , Token } ;
2
3
use std:: io:: { ErrorKind , Read , Write } ;
3
4
4
5
fn get_req ( path : & str ) -> String {
@@ -46,9 +47,6 @@ impl Future for HttpGetFuture {
46
47
type Output = String ;
47
48
48
49
fn poll ( & mut self ) -> PollState < Self :: Output > {
49
- // If this is first time polled, start the operation
50
- // see: https://users.rust-lang.org/t/is-it-bad-behaviour-for-a-future-or-stream-to-do-something-before-being-polled/61353
51
- // Avoid dns lookup this time
52
50
if self . stream . is_none ( ) {
53
51
println ! ( "FIRST POLL - START OPERATION" ) ;
54
52
self . write_request ( ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ pub struct Http;
15
15
16
16
impl Http {
17
17
pub fn get ( path : & str ) -> impl Future < Output = String > {
18
- HttpGetFuture :: new ( path. to_string ( ) )
18
+ HttpGetFuture :: new ( path)
19
19
}
20
20
}
21
21
@@ -26,11 +26,11 @@ struct HttpGetFuture {
26
26
}
27
27
28
28
impl HttpGetFuture {
29
- fn new ( path : String ) -> Self {
29
+ fn new ( path : & str ) -> Self {
30
30
Self {
31
31
stream : None ,
32
32
buffer : vec ! [ ] ,
33
- path,
33
+ path : path . to_string ( ) ,
34
34
}
35
35
}
36
36
@@ -50,12 +50,11 @@ impl Future for HttpGetFuture {
50
50
if self . stream . is_none ( ) {
51
51
println ! ( "FIRST POLL - START OPERATION" ) ;
52
52
self . write_request ( ) ;
53
-
53
+
54
54
// CHANGED
55
55
runtime:: registry ( )
56
56
. register ( self . stream . as_mut ( ) . unwrap ( ) , Token ( 0 ) , Interest :: READABLE )
57
57
. unwrap ( ) ;
58
- // ============
59
58
}
60
59
61
60
let mut buff = vec ! [ 0u8 ; 4096 ] ;
@@ -72,7 +71,9 @@ impl Future for HttpGetFuture {
72
71
Err ( e) if e. kind ( ) == ErrorKind :: WouldBlock => {
73
72
break PollState :: NotReady ;
74
73
}
75
-
74
+ Err ( e) if e. kind ( ) == ErrorKind :: Interrupted => {
75
+ continue ;
76
+ }
76
77
Err ( e) => panic ! ( "{e:?}" ) ,
77
78
}
78
79
}
You can’t perform that action at this time.
0 commit comments