Browse Source

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

whitequark 8 years ago
parent
commit
d5638f469f
2 changed files with 5 additions and 3 deletions
  1. 1 1
      examples/server.rs
  2. 4 2
      src/socket/udp.rs

+ 1 - 1
examples/server.rs

@@ -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();
             }
         }
 

+ 4 - 2
src/socket/udp.rs

@@ -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.