1
1
//! # FIXES:
2
- //!
2
+ //!
3
3
//! The number is identical to the number in the GitHub issue tracker
4
4
//!
5
5
//! ## FIX ISSUE #4:
6
- //!
6
+ //!
7
7
//! See:https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/issues/4
8
8
//! Some users reported false event notification causing the counter to increase
9
9
//! due to the OS reporting a READ event after we already read the TcpStream to EOF.
13
13
//! The fix for this is to account for false wakeups which is an easy fix but requires
14
14
//! a few changes to the example. I've added an explicit comment: "FIX #4", the places
15
15
//! I made a change so it's easy to spot the differences to the example code in the book.
16
- //!
16
+ //!
17
17
//! ## TROUBLESHOOTING (KNOWN POTENTIAL ISSUE)
18
- //!
18
+ //!
19
19
//! ### EXAMPLE DOESN'T WORK AS EXPECTED - PROBLEM WITH DNS LOOKUP
20
20
//! If you first run this example on Linux under WSL and then immediately run it on
21
21
//! Windows, I've observed issues with the DNS lookup for "localhost" being so slow
22
22
//! that it defeats the purpose of the example. This issue could potentially also
23
23
//! happen under other scenarios than the one mentioned here and the fix will be
24
24
//! 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
+ //!
29
29
//! Change `let addr = "localhost:8080";` to `let addr = "127.0.0.1:8080";`.
30
30
//!
31
31
@@ -58,9 +58,7 @@ fn handle_events(events: &[Event], streams: &mut [TcpStream], handled: &mut Hash
58
58
match streams[ index] . read ( & mut data) {
59
59
Ok ( n) if n == 0 => {
60
60
// 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.
64
62
if !handled. insert ( index) {
65
63
break ;
66
64
}
@@ -117,7 +115,7 @@ fn main() -> Result<()> {
117
115
118
116
streams. push ( stream) ;
119
117
}
120
-
118
+
121
119
// FIX #4: store the handled IDs
122
120
let mut handled_ids = HashSet :: new ( ) ;
123
121
@@ -139,7 +137,7 @@ fn main() -> Result<()> {
139
137
// Events collection
140
138
let events: Vec < Event > = events. into_iter ( ) . map ( |e| e. clone ( ) ) . collect ( ) ;
141
139
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142
-
140
+
143
141
// ------------------------------------------------------⌄ FIX #4 (new signature)
144
142
handled_events += handle_events ( & events, & mut streams, & mut handled_ids) ?;
145
143
}
0 commit comments