I believe that the placement of the call to pool.scoped inside the loop statement isn't taking advantage of the thread pool. As it stands, I think only one connection at a time is being processed. The example in the scoped_threadpool documentation suggests that the entire loop be enclosed in the Pool::scoped closure.
|
loop { |
|
// Incoming is an endless iterator, so it's okay to unwrap on it. |
|
let stream = incoming.next().unwrap(); |
|
let stream = stream.expect("Error handling TCP stream."); |
|
|
|
stream |
|
.set_read_timeout(Some(Duration::from_millis(READ_TIMEOUT_MS))) |
|
.expect("FATAL: Couldn't set read timeout on socket"); |
|
|
|
pool.scoped(|scope| { |
|
scope.execute(|| { |
|
self.handle_connection(stream) |
|
.expect("Error handling connection."); |
|
}); |
|
}); |
|
} |
I believe that the placement of the call to
pool.scopedinside theloopstatement isn't taking advantage of the thread pool. As it stands, I think only one connection at a time is being processed. The example in thescoped_threadpooldocumentation suggests that the entire loop be enclosed in thePool::scopedclosure.simple-server/src/lib.rs
Lines 254 to 269 in 10103f5