Skip to content

Commit 61bba94

Browse files
committed
minor changes to get the different versions/edits to line up better
1 parent a7f6865 commit 61bba94

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

ch8/a-coroutine/src/http.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::future::{Future, PollState};
1+
use crate::{future::PollState, runtime, Future};
2+
use mio::{Interest, Token};
23
use std::io::{ErrorKind, Read, Write};
34

45
fn get_req(path: &str) -> String {
@@ -46,9 +47,6 @@ impl Future for HttpGetFuture {
4647
type Output = String;
4748

4849
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
5250
if self.stream.is_none() {
5351
println!("FIRST POLL - START OPERATION");
5452
self.write_request();

ch9/a-runtime/src/http.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Http;
1515

1616
impl Http {
1717
pub fn get(path: &str) -> impl Future<Output = String> {
18-
HttpGetFuture::new(path.to_string())
18+
HttpGetFuture::new(path)
1919
}
2020
}
2121

@@ -26,11 +26,11 @@ struct HttpGetFuture {
2626
}
2727

2828
impl HttpGetFuture {
29-
fn new(path: String) -> Self {
29+
fn new(path: &str) -> Self {
3030
Self {
3131
stream: None,
3232
buffer: vec![],
33-
path,
33+
path: path.to_string(),
3434
}
3535
}
3636

@@ -50,12 +50,11 @@ impl Future for HttpGetFuture {
5050
if self.stream.is_none() {
5151
println!("FIRST POLL - START OPERATION");
5252
self.write_request();
53-
53+
5454
// CHANGED
5555
runtime::registry()
5656
.register(self.stream.as_mut().unwrap(), Token(0), Interest::READABLE)
5757
.unwrap();
58-
// ============
5958
}
6059

6160
let mut buff = vec![0u8; 4096];
@@ -72,7 +71,9 @@ impl Future for HttpGetFuture {
7271
Err(e) if e.kind() == ErrorKind::WouldBlock => {
7372
break PollState::NotReady;
7473
}
75-
74+
Err(e) if e.kind() == ErrorKind::Interrupted => {
75+
continue;
76+
}
7677
Err(e) => panic!("{e:?}"),
7778
}
7879
}

0 commit comments

Comments
 (0)