Return the amount of bytes sent from UdpSocket::send_slice.

v0.7.x
whitequark 2017-01-11 06:37:00 +00:00
parent f01ce30466
commit 7f095f6429
2 changed files with 5 additions and 3 deletions

View File

@ -118,7 +118,7 @@ fn main() {
let data = b"yo dawg\n";
debug!("udp:6969 send data: {:?}",
str::from_utf8(data.as_ref()).unwrap());
socket.send_slice(data, endpoint).unwrap()
socket.send_slice(data, endpoint).unwrap();
}
}

View File

@ -155,9 +155,11 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
/// Enqueue a packet to be sent to a given remote endpoint, and fill it from a slice.
///
/// See also [send](#method.send).
pub fn send_slice(&mut self, data: &[u8], endpoint: IpEndpoint) -> Result<(), Error> {
pub fn send_slice(&mut self, data: &[u8], endpoint: IpEndpoint) -> Result<usize, Error> {
let buffer = try!(self.send(data.len(), endpoint));
Ok(buffer.copy_from_slice(data))
let data = &data[..buffer.len()];
buffer.copy_from_slice(data);
Ok(data.len())
}
/// Check whether the receive buffer is full.