Why would the first write to Mio's TcpStream a

2019-08-27 04:12发布

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
0条回答
登录 后发表回答