Why would the first write to Mio's TcpStream a

2019-08-27 04:36发布

问题:

With this code:

poll.poll(&mut poll_events, Some(Duration::from_secs(0)));
for event in poll_events.iter() {
    match event.token() {
        LISTENER_TOKEN => {
            let (mut stream, addr) = unwrap_or_continue!(
                listener.accept(),
                "Failed to accept incoming connection"
            );
            unwrap_or_continue!(
                stream.write("Hello, world!\n".as_bytes()),
                &format!("Failed to write to {}", addr)
            );
        }
        _ => unreachable!()
    }
}

where unwrap_or_continue! just does continue on an error while reporting it, I get this error:

Failed to write to 127.0.0.1:49231: operation would block

Why would it block, the socket just got accepted and it's a first write?

标签: rust mio