Why would the first write to Mio's TcpStream after accepting give an “operation would block” error?

血红的双手。 提交于 2019-12-25 01:36:00

问题


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?

来源:https://stackoverflow.com/questions/49886603/why-would-the-first-write-to-mios-tcpstream-after-accepting-give-an-operation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!