The main program 89 If there are events to be handled, we pass these on to the handle_events function together with a mutable reference to our streams collection. The last part of main is simply to write FINISHED to the console to let us know we exited main at that point. The last bit of code in this chapter is the handle_events function. This function takes two arguments, a slice of Event structs and a mutable slice of Tcp Stream objects. Let's take a look at the code before we explain it: fn handle_events(events: &[Event], streams: &mut [Tcp Stream])-> Result<usize> { let mut handled_events = 0; for event in events { let index = event. token(); let mut data = vec![0u8; 4096]; loop { match streams[index]. read(&mut data) { Ok(n) if n == 0 => { handled_events += 1; break; } Ok(n) => { let txt = String::from_utf8_lossy(&data[..n]); println!("RECEIVED: {:?}", event); println!("{txt}\n------\n"); } // Not ready to read in a non-blocking manner. This could // happen even if the event was reported as ready Err(e) if e. kind() == io::Error Kind::Would Block => break, Err(e) => return Err(e), } } } Ok(handled_events) } The first thing we do is to create a variable, handled_events, to track how many events we consider handled on each wakeup. The next step is looping through the events we received.