Skip to content

Commit 56034ee

Browse files
committed
documentation fix
1 parent 22d8c08 commit 56034ee

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

ch04/a-epoll/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ fn handle_events(
5151
match streams[index].read(&mut data) {
5252
Ok(n) if n == 0 => {
5353
// FIX #4
54-
// `insert` returns false if the value already existed in the set. We
55-
// handle it here since we must be sure that the TcpStream is fully
56-
// drained due to using edge triggered epoll.
54+
// `insert` returns false if the value already existed in the set.
5755
if !handled.insert(index) {
5856
break;
5957
}

ch04/b-epoll-mio/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! # FIXES:
2-
//!
2+
//!
33
//! The number is identical to the number in the GitHub issue tracker
44
//!
55
//! ## FIX ISSUE #4:
6-
//!
6+
//!
77
//! See:https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/4
88
//! Some users reported false event notification causing the counter to increase
99
//! due to the OS reporting a READ event after we already read the TcpStream to EOF.
@@ -13,19 +13,19 @@
1313
//! The fix for this is to account for false wakeups which is an easy fix but requires
1414
//! a few changes to the example. I've added an explicit comment: "FIX #4", the places
1515
//! I made a change so it's easy to spot the differences to the example code in the book.
16-
//!
16+
//!
1717
//! ## TROUBLESHOOTING (KNOWN POTENTIAL ISSUE)
18-
//!
18+
//!
1919
//! ### EXAMPLE DOESN'T WORK AS EXPECTED - PROBLEM WITH DNS LOOKUP
2020
//! If you first run this example on Linux under WSL and then immediately run it on
2121
//! Windows, I've observed issues with the DNS lookup for "localhost" being so slow
2222
//! that it defeats the purpose of the example. This issue could potentially also
2323
//! happen under other scenarios than the one mentioned here and the fix will be
2424
//! the same regardless.
25-
//!
26-
//! I don't consider this a bug with our code but a surprising behavior of the
27-
//! WSL/Windows network stack. Anyway, if you encounter this, the fix is simple:
28-
//!
25+
//!
26+
//! I don't consider this a bug with our code but a surprising behavior of the
27+
//! WSL/Windows network stack. Anyway, if you encounter this, the fix is simple:
28+
//!
2929
//! Change `let addr = "localhost:8080";` to `let addr = "127.0.0.1:8080";`.
3030
//!
3131
@@ -58,9 +58,7 @@ fn handle_events(events: &[Event], streams: &mut [TcpStream], handled: &mut Hash
5858
match streams[index].read(&mut data) {
5959
Ok(n) if n == 0 => {
6060
// FIX #4
61-
// `insert` returns false if the value already existed in the set. We
62-
// handle it here since we must be sure that the TcpStream is fully
63-
// drained due to using edge triggered epoll.
61+
// `insert` returns false if the value already existed in the set.
6462
if !handled.insert(index) {
6563
break;
6664
}
@@ -117,7 +115,7 @@ fn main() -> Result<()> {
117115

118116
streams.push(stream);
119117
}
120-
118+
121119
// FIX #4: store the handled IDs
122120
let mut handled_ids = HashSet::new();
123121

@@ -139,7 +137,7 @@ fn main() -> Result<()> {
139137
// Events collection
140138
let events: Vec<Event> = events.into_iter().map(|e| e.clone()).collect();
141139
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142-
140+
143141
// ------------------------------------------------------⌄ FIX #4 (new signature)
144142
handled_events += handle_events(&events, &mut streams, &mut handled_ids)?;
145143
}

0 commit comments

Comments
 (0)