diff --git a/src/stream/tcb.rs b/src/stream/tcb.rs index ff44486..ab071ad 100644 --- a/src/stream/tcb.rs +++ b/src/stream/tcb.rs @@ -62,17 +62,17 @@ impl Tcb { unordered_packets: BTreeMap::new(), } } - pub(super) fn add_inflight_packet(&mut self, seq: u32, buf: &[u8]) { - self.inflight_packets - .push(InflightPacket::new(seq, buf.to_vec())); - self.seq = self.seq.wrapping_add(buf.len() as u32); + pub(super) fn add_inflight_packet(&mut self, seq: u32, buf: Vec) { + let buf_len = buf.len() as u32; + self.inflight_packets.push(InflightPacket::new(seq, buf)); + self.seq = self.seq.wrapping_add(buf_len); } - pub(super) fn add_unordered_packet(&mut self, seq: u32, buf: &[u8]) { + pub(super) fn add_unordered_packet(&mut self, seq: u32, buf: Vec) { if seq < self.ack { return; } self.unordered_packets - .insert(seq, UnorderedPacket::new(buf.to_vec())); + .insert(seq, UnorderedPacket::new(buf)); } pub(super) fn get_available_read_buffer_size(&self) -> usize { READ_BUFFER_SIZE.saturating_sub( diff --git a/src/stream/tcp.rs b/src/stream/tcp.rs index b5aa424..8e481f7 100644 --- a/src/stream/tcp.rs +++ b/src/stream/tcp.rs @@ -325,10 +325,8 @@ impl AsyncRead for IpStackTcpStream { // } self.tcb.change_last_ack(t.inner().acknowledgment_number); - self.tcb.add_unordered_packet( - t.inner().sequence_number, - &p.payload, - ); + self.tcb + .add_unordered_packet(t.inner().sequence_number, p.payload); // buf.put_slice(&p.payload); // self.tcb.add_ack(p.payload.len() as u32); // self.packet_to_send = Some(self.create_rev_packet( @@ -389,7 +387,7 @@ impl AsyncRead for IpStackTcpStream { // )?); // return Poll::Ready(Ok(())); self.tcb - .add_unordered_packet(t.inner().sequence_number, &p.payload); + .add_unordered_packet(t.inner().sequence_number, p.payload); continue; } } else if self.tcb.get_state() == TcpState::FinWait1(false) { @@ -455,7 +453,7 @@ impl AsyncWrite for IpStackTcpStream { self.packet_sender .send(packet) .or(Err(ErrorKind::UnexpectedEof))?; - self.tcb.add_inflight_packet(seq, &payload); + self.tcb.add_inflight_packet(seq, payload); Poll::Ready(Ok(payload_len)) }