浏览代码

Match the behavior of peek_slice to recv_slice

Erika Hunhoff 1 年之前
父节点
当前提交
86d4cf1053
共有 1 个文件被更改,包括 1 次插入4 次删除
  1. 1 4
      src/socket/tcp.rs

+ 1 - 4
src/socket/tcp.rs

@@ -1173,10 +1173,7 @@ impl<'a> Socket<'a> {
     ///
     /// This function otherwise behaves identically to [recv_slice](#method.recv_slice).
     pub fn peek_slice(&mut self, data: &mut [u8]) -> Result<usize, RecvError> {
-        let buffer = self.peek(data.len())?;
-        let data = &mut data[..buffer.len()];
-        data.copy_from_slice(buffer);
-        Ok(buffer.len())
+        Ok(self.rx_buffer.read_allocated(0, data))
     }
 
     /// Return the amount of octets queued in the transmit buffer.