Skip to content

non-blocking stream & io::Write::write_all method are not compatible and result in unexpected user behavior #115483

Closed
@softstream-link

Description

@softstream-link

Location

This is a continuation of #115451

Summary

The following block of code has unexpected behavior as it will likely not write_all bytes to the stream but there is no way for user to know who many if any where written.

Perhaps the trait should take a mut buf: &[u8] so that the user can check? In either case it is a very hard issue to troubleshot as it fails only on some platforms and under certain conditions yet there is no mention anywhere that nonblocking sockets and io::Write ::write_all method are not compatible.

let mut stream = TcpStream::connect(add).unwrap();
stream.nonblocking(true).unwrap()
let buf = [1,2,3,4,5];
// THIS LINE WILL sometime propagate a WouldBlock error kind however it would have written X number of bytes to the steam with out a way too tell if X is =0 or X<buf.len()
stream.write_all(&buf[..]);  

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions