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 buff… #740

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ impl UdpSocket {
self.sys.send_to(buf, target).map_non_block()
}

/// Receives data from the socket. On success, returns the number of bytes
/// read and the address from whence the data came.
/// Receives data from the socket and stores data in the supplied buffer `buf`. On success,
/// returns the number of bytes read and the address from whence the data came.
///
/// The function must be called with valid byte array `buf` of sufficient size to
/// hold the message bytes. If a message is too long to fit in the supplied buffer,
/// excess bytes may be discarded.
///
/// The function does not read from `buf`, but is overwriting previous content of `buf`.
///
/// Assuming the function has read `n` bytes, slicing `&buf[..n]` provides
/// efficient access with iterators and boundary checks.
pub fn recv_from(&self, buf: &mut [u8])
-> io::Result<Option<(usize, SocketAddr)>> {
self.sys.recv_from(buf).map_non_block()
Expand All @@ -94,8 +103,17 @@ impl UdpSocket {
self.sys.send(buf).map_non_block()
}

/// Receives data from the socket previously bound with connect(). On success, returns
/// the number of bytes read and the address from whence the data came.
/// Receives data from the socket previously bound with connect() and stores data in
/// the supplied buffer `buf`. On success, returns the number of bytes read.
///
/// The function must be called with valid byte array `buf` of sufficient size to
/// hold the message bytes. If a message is too long to fit in the supplied buffer,
/// excess bytes may be discarded.
///
/// The function does not read from `buf`, but is overwriting previous content of `buf`.
///
/// Assuming the function has read `n` bytes, slicing `&buf[..n]` provides
/// efficient access with iterators and boundary checks.
pub fn recv(&self, buf: &mut [u8])
-> io::Result<Option<usize>> {
self.sys.recv(buf).map_non_block()
Expand Down