Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that UdpSocket::recv and recv_from do not read from the buffer #657

Closed
dtolnay opened this issue Aug 18, 2017 · 6 comments
Closed

Comments

@dtolnay
Copy link

dtolnay commented Aug 18, 2017

fn recv(&self, buf: &mut [u8]) -> Result<usize>;
fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>;

It is important for these to document that they only write to the buffer, not read from it, because that means it is safe to pass an uninitialized buffer. It would be wasteful to construct a buffer, initialize it to contain all 0 bytes, and pass it to UdpSocket.

@frehberg
Copy link
Contributor

frehberg commented Aug 30, 2017

And add to the docs, if recv returns with Ok(N), the following code must not iterate over complete array, but iterate over a slice of the array buf[0,..,N-1].

frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 15, 2017
@frehberg
Copy link
Contributor

can be closed?

@dtolnay
Copy link
Author

dtolnay commented Sep 15, 2017

@frehberg
Copy link
Contributor

frehberg commented Dec 6, 2017

Finally the patch has been rebased, and could be merged

@carllerche
Copy link
Member

The original PR got messed up somehow. I moved the commit to #775.

@carllerche
Copy link
Member

Thanks. This has been merged (f6f293f).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants