Create Your Own Event Queue 88 To continue with the code, the next step is setting Tcp Stream to non-blocking by calling Tcp Stream::set_nonblocking(true). After that, we write our request to the server before we register interest in read events by setting the EPOLLIN flag bit in the interests bitmask. For each iteration, we push the stream to the end of our streams collection. The next part of the main function is handling incoming events. Let's take a look at the last part of our main function: let mut handled_events = 0; while handled_events < n_events { let mut events = Vec::with_capacity(10); poll. poll(&mut events, None)?; if events. is_empty() { println!("TIMEOUT (OR SPURIOUS EVENT NOTIFICATION)"); continue; } handled_events += handle_events(&events, &mut streams)?; } println!("FINISHED"); Ok(()) } The first thing we do is create a variable called handled_events to track how many events we have handled. Next is our event loop. We loop as long as the handled events are less than the number of events we expect. Once all events are handled, we exit the loop. Inside the loop, we create a Vec<Event> with the capacity to store 10 events. It's important that we create this using Vec::with_capacity since the operating system will assume that we pass it memory that we've allocated. We could choose any number of events here and it would work just fine, but setting too low a number would limit how many events the operating system could notify us about on each wakeup. Next is our blocking call to Poll::poll. As you know, this will actually tell the operating system to park our thread and wake us up when an event has occurred. If we're woken up, but there are no events in the list, it's either a timeout or a spurious event (which could happen, so we need a way to check whether a timeout has actually elapsed if that's important to us). If that's the case, we simply call Poll::poll once more.