pub fn receive_segment<T: NetworkBytes>(
        &mut self,
        s: &TcpSegment<T>,
        buf: &mut [u8],
        now: u64,
    ) -> Result<(Option<NonZeroUsize>, RecvStatusFlags), RecvError> {
        if self.rst_pending() || self.is_reset() {
            return Err(RecvError::ConnectionReset);
        }

        // TODO: The following logic fully makes sense only for a passive open (which is what we
        // currently support). Things must change a bit if/when we also implement active opens.

        let segment_flags = s.flags_after_ns();

        if segment_flags.intersects(TcpFlags::RST) {
            let seq = Wrapping(s.sequence_number());
            // We accept the RST only if it carries an in-window sequence number.
            // TODO: If/when we support active opens, we'll also have to accept RST/SYN segments,
            // which must acknowledge our SYN to be valid.
            if seq_at_or_after(seq, self.ack_to_send) && seq_after(self.local_rwnd_edge, seq) {
                self.set_flags(ConnStatusFlags::RESET);
                return Ok((None, RecvStatusFlags::RESET_RECEIVED));
            } else {
                return Ok((None, RecvStatusFlags::INVALID_RST));
            }
        }

        let payload_len = s.len() - s.header_len();
        let mut recv_status_flags = RecvStatusFlags::empty();

        if !self.synack_sent() {
            // We received another segment before getting the chance to send a SYNACK. It's either
            // a retransmitted SYN, or something that does not make sense.
            if self.is_same_syn(s) {
                return Ok((None, recv_status_flags));
            } else {
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        } else if !self.is_established() {
            // So at this point we've sent at least one SYNACK, but the connection is not
            // ESTABLISHED yet. We only accept SYN retransmissions and ACKs. I'm not sure that
            // it's completely forbidden to sent an ACK + data in response to a SYNACK, so we don't
            // complain about non-pure ACKs (or even data + ACK + FIN segments).
            if self.is_same_syn(s) {
                // Maybe our previous SYNACK got lost or smt, so clear SYN_ACK_SENT to resend it.
                self.clear_flags(ConnStatusFlags::SYNACK_SENT);
                return Ok((None, recv_status_flags));
            } else if segment_flags.intersects(TcpFlags::SYN) {
                // So we basically freak out over SYN segments which are not valid SYN
                // retransmission.
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        } else {
            // Reaching this branch means the connection is ESTABLISHED. The only thing we want to
            // do right now is reset if we get segments which carry the SYN flag, because they are
            // obviously invalid, and something must be really wrong.
            // TODO: Is it an overreaction to reset here?
            if s.flags_after_ns().intersects(TcpFlags::SYN) {
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        }

        // The ACK number can only be valid when ACK flag is set. The following logic applies to
        // pretty much all connection states which can reach this point.
        if segment_flags.intersects(TcpFlags::ACK) {
            let ack = Wrapping(s.ack_number());

            if seq_at_or_after(ack, self.highest_ack_received)
                && seq_at_or_after(self.first_not_sent, ack)
            {
                // This is a valid ACK. Reset rto_count, since this means the other side is still
                // alive and kicking (or ACking).
                self.rto_count = 0;

                if ack == self.highest_ack_received && ack != self.first_not_sent {
                    if !self.is_established() {
                        // Just kidding, a DUPACK is not valid before the connection is ESTABLISHED.
                        return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_ACK);
                    }
                    // Duplicate ACKs can only increase in sequence number, so there's no need
                    // to check if this one is older than self.dup_ack.
                    self.dup_ack = true;
                    recv_status_flags |= RecvStatusFlags::DUP_ACK;
                } else {
                    // We're making progress. We should also reset rto_start in this case.
                    self.highest_ack_received = ack;
                    self.rto_start = now;
                    if !self.is_established() && self.synack_sent() {
                        // The connection becomes ESTABLISHED.
                        self.set_flags(ConnStatusFlags::ESTABLISHED);
                    }

                    if self.fin_sent() && ack == self.first_not_sent {
                        self.set_flags(ConnStatusFlags::FIN_ACKED);
                    }
                }

                // Look for remote remote rwnd updates.
                if self.is_established() {
                    let edge = self.compute_remote_rwnd_edge(ack, s.window_size());
                    if seq_after(edge, self.remote_rwnd_edge) {
                        self.remote_rwnd_edge = edge;
                    } else if edge != self.remote_rwnd_edge {
                        // The right edge of the remote receive window has been moved to the left,
                        // or has been set to an invalid value. Both cases represent erroneous TCP
                        // behaviour.
                        recv_status_flags |= RecvStatusFlags::REMOTE_RWND_EDGE;
                    }
                }
            } else {
                recv_status_flags |= RecvStatusFlags::INVALID_ACK;
                if !self.is_established() {
                    // Reset the connection if we receive an invalid ACK before reaching the
                    // ESTABLISHED state.
                    return self.reset_for_segment_helper(s, recv_status_flags);
                }
            }
        }

        // We start looking at the payload and/or FIN next. This makes sense only if the
        // connection is established.
        if !self.is_established() {
            return Ok((None, recv_status_flags));
        }

        let seq = Wrapping(s.sequence_number());
        let wrapping_payload_len = Wrapping(payload_len as u32);

        if payload_len > buf.len() {
            return Err(RecvError::BufferTooSmall);
        }

        let mut enqueue_ack = if payload_len > 0 {
            let data_end_seq = seq + wrapping_payload_len;

            if let Some(fin_seq) = self.fin_received {
                if !seq_at_or_after(fin_seq, data_end_seq) {
                    // TODO: This is a strange situation, because the other endpoint is sending data
                    // after it initially closed its half of the connection. We simply ignore the
                    // segment for now.
                    return Ok((None, recv_status_flags | RecvStatusFlags::DATA_BEYOND_FIN));
                }
            }

            if !seq_at_or_after(self.local_rwnd_edge, data_end_seq) {
                // TODO: This is another strange (and potentially dangerous) situation, because
                // either we or the other endpoint broke receive window semantics. We simply ignore
                // the segment for now.
                return Ok((
                    None,
                    recv_status_flags | RecvStatusFlags::SEGMENT_BEYOND_RWND,
                ));
            }

            // We currently assume segments are seldom lost or reordered, and only accept those with
            // the exact next sequence number we're waiting for.
            if seq != self.ack_to_send {
                // TODO: Maybe we should enqueue multiple ACKs here (after making such a thing
                // possible in the first place), just so we're more likely to trigger a
                // retransmission.
                self.enqueue_ack();
                return Ok((None, recv_status_flags | RecvStatusFlags::UNEXPECTED_SEQ));
            }

            self.ack_to_send = data_end_seq;
            true
        } else {
            false
        };

        // We assume the sequence number of the FIN does not change via conflicting FIN carrying
        // segments (as it should be the case during TCP normal operation). It the other endpoint
        // breaks this convention, it will have to deal with potentially hanging (until timing out)
        // connections and/or RST segments.
        if segment_flags.intersects(TcpFlags::FIN) && !self.fin_received() {
            let fin_seq = seq + wrapping_payload_len;

            // In order to avoid some complexity on our side, we only accept an incoming FIN if its
            // sequence number matches that of the first byte yet to be received (this is similar to
            // what we do for data segments right now).
            if fin_seq == self.ack_to_send {
                self.fin_received = Some(fin_seq);
                // Increase this to also ACK the FIN.
                self.ack_to_send += Wrapping(1);
                enqueue_ack = true;
            } else {
                recv_status_flags |= RecvStatusFlags::INVALID_FIN;
            }
        }

        if enqueue_ack {
            self.enqueue_ack();

            // We check this here because if a valid payload has been received, then we must have
            // set enqueue_ack = true earlier.
            if payload_len > 0 {
                buf[..payload_len].copy_from_slice(s.payload());
                // The unwrap is safe because payload_len > 0.
                return Ok((
                    Some(NonZeroUsize::new(payload_len).unwrap()),
                    recv_status_flags,
                ));
            }
        }

        Ok((None, recv_status_flags))
    }
/// Handles an incoming segment.
///
/// When no errors occur, returns a pair consisting of how many
/// bytes (if any) were received, and whether any unusual conditions arose while processing the
/// segment. Since a `Connection` does not have its own internal buffer, `buf` is required to
/// store any data carried by incoming segments.
///
/// # Arguments
///
/// * `s` - The incoming segment.
/// * `buf` - The receive buffer where payload data (if any) from `s` is going to be written.
/// * `now` - An opaque timestamp representing the current moment in time.
Handles an incoming segment.
When no errors occur, returns a pair consisting of how many
bytes (if any) were received, and whether any unusual conditions arose while processing the
segment. Since a `Connection` does not have its own internal buffer, `buf` is required to
store any data carried by incoming segments.
Handles an incoming segment . When no errors occur returns a pair consisting of how many bytes ( if any ) were received and whether any unusual conditions arose while processing the segment . Since a ` Connection ` does not have its own internal buffer ` buf ` is required to store any data carried by incoming segments .
pub fn receive_segment<T: NetworkBytes>(
        &mut self,
        s: &TcpSegment<T>,
        buf: &mut [u8],
        now: u64,
    ) -> Result<(Option<NonZeroUsize>, RecvStatusFlags), RecvError> {
        if self.rst_pending() || self.is_reset() {
            return Err(RecvError::ConnectionReset);
        }
        // TODO: The following logic fully makes sense only for a passive open (which is what we
        // currently support). Things must change a bit if/when we also implement active opens.
        let segment_flags = s.flags_after_ns();
        if segment_flags.intersects(TcpFlags::RST) {
            let seq = Wrapping(s.sequence_number());
            // We accept the RST only if it carries an in-window sequence number.
            // TODO: If/when we support active opens, we'll also have to accept RST/SYN segments,
            // which must acknowledge our SYN to be valid.
            if seq_at_or_after(seq, self.ack_to_send) && seq_after(self.local_rwnd_edge, seq) {
                self.set_flags(ConnStatusFlags::RESET);
                return Ok((None, RecvStatusFlags::RESET_RECEIVED));
            } else {
                return Ok((None, RecvStatusFlags::INVALID_RST));
            }
        }
        let payload_len = s.len() - s.header_len();
        let mut recv_status_flags = RecvStatusFlags::empty();
        if !self.synack_sent() {
            // We received another segment before getting the chance to send a SYNACK. It's either
            // a retransmitted SYN, or something that does not make sense.
            if self.is_same_syn(s) {
                return Ok((None, recv_status_flags));
            } else {
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        } else if !self.is_established() {
            // So at this point we've sent at least one SYNACK, but the connection is not
            // ESTABLISHED yet. We only accept SYN retransmissions and ACKs. I'm not sure that
            // it's completely forbidden to sent an ACK + data in response to a SYNACK, so we don't
            // complain about non-pure ACKs (or even data + ACK + FIN segments).
            if self.is_same_syn(s) {
                // Maybe our previous SYNACK got lost or smt, so clear SYN_ACK_SENT to resend it.
                self.clear_flags(ConnStatusFlags::SYNACK_SENT);
                return Ok((None, recv_status_flags));
            } else if segment_flags.intersects(TcpFlags::SYN) {
                // So we basically freak out over SYN segments which are not valid SYN
                // retransmission.
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        } else {
            // Reaching this branch means the connection is ESTABLISHED. The only thing we want to
            // do right now is reset if we get segments which carry the SYN flag, because they are
            // obviously invalid, and something must be really wrong.
            // TODO: Is it an overreaction to reset here?
            if s.flags_after_ns().intersects(TcpFlags::SYN) {
                return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_SEGMENT);
            }
        }
        // The ACK number can only be valid when ACK flag is set. The following logic applies to
        // pretty much all connection states which can reach this point.
        if segment_flags.intersects(TcpFlags::ACK) {
            let ack = Wrapping(s.ack_number());
            if seq_at_or_after(ack, self.highest_ack_received)
                && seq_at_or_after(self.first_not_sent, ack)
            {
                // This is a valid ACK. Reset rto_count, since this means the other side is still
                // alive and kicking (or ACking).
                self.rto_count = 0;
                if ack == self.highest_ack_received && ack != self.first_not_sent {
                    if !self.is_established() {
                        // Just kidding, a DUPACK is not valid before the connection is ESTABLISHED.
                        return self.reset_for_segment_helper(s, RecvStatusFlags::INVALID_ACK);
                    }
                    // Duplicate ACKs can only increase in sequence number, so there's no need
                    // to check if this one is older than self.dup_ack.
                    self.dup_ack = true;
                    recv_status_flags |= RecvStatusFlags::DUP_ACK;
                } else {
                    // We're making progress. We should also reset rto_start in this case.
                    self.highest_ack_received = ack;
                    self.rto_start = now;
                    if !self.is_established() && self.synack_sent() {
                        // The connection becomes ESTABLISHED.
                        self.set_flags(ConnStatusFlags::ESTABLISHED);
                    }
                    if self.fin_sent() && ack == self.first_not_sent {
                        self.set_flags(ConnStatusFlags::FIN_ACKED);
                    }
                }
                // Look for remote remote rwnd updates.
                if self.is_established() {
                    let edge = self.compute_remote_rwnd_edge(ack, s.window_size());
                    if seq_after(edge, self.remote_rwnd_edge) {
                        self.remote_rwnd_edge = edge;
                    } else if edge != self.remote_rwnd_edge {
                        // The right edge of the remote receive window has been moved to the left,
                        // or has been set to an invalid value. Both cases represent erroneous TCP
                        // behaviour.
                        recv_status_flags |= RecvStatusFlags::REMOTE_RWND_EDGE;
                    }
                }
            } else {
                recv_status_flags |= RecvStatusFlags::INVALID_ACK;
                if !self.is_established() {
                    // Reset the connection if we receive an invalid ACK before reaching the
                    // ESTABLISHED state.
                    return self.reset_for_segment_helper(s, recv_status_flags);
                }
            }
        }
        // We start looking at the payload and/or FIN next. This makes sense only if the
        // connection is established.
        if !self.is_established() {
            return Ok((None, recv_status_flags));
        }
        let seq = Wrapping(s.sequence_number());
        let wrapping_payload_len = Wrapping(payload_len as u32);
        if payload_len > buf.len() {
            return Err(RecvError::BufferTooSmall);
        }
        let mut enqueue_ack = if payload_len > 0 {
            let data_end_seq = seq + wrapping_payload_len;
            if let Some(fin_seq) = self.fin_received {
                if !seq_at_or_after(fin_seq, data_end_seq) {
                    // TODO: This is a strange situation, because the other endpoint is sending data
                    // after it initially closed its half of the connection. We simply ignore the
                    // segment for now.
                    return Ok((None, recv_status_flags | RecvStatusFlags::DATA_BEYOND_FIN));
                }
            }
            if !seq_at_or_after(self.local_rwnd_edge, data_end_seq) {
                // TODO: This is another strange (and potentially dangerous) situation, because
                // either we or the other endpoint broke receive window semantics. We simply ignore
                // the segment for now.
                return Ok((
                    None,
                    recv_status_flags | RecvStatusFlags::SEGMENT_BEYOND_RWND,
                ));
            }
            // We currently assume segments are seldom lost or reordered, and only accept those with
            // the exact next sequence number we're waiting for.
            if seq != self.ack_to_send {
                // TODO: Maybe we should enqueue multiple ACKs here (after making such a thing
                // possible in the first place), just so we're more likely to trigger a
                // retransmission.
                self.enqueue_ack();
                return Ok((None, recv_status_flags | RecvStatusFlags::UNEXPECTED_SEQ));
            }
            self.ack_to_send = data_end_seq;
            true
        } else {
            false
        };
        // We assume the sequence number of the FIN does not change via conflicting FIN carrying
        // segments (as it should be the case during TCP normal operation). It the other endpoint
        // breaks this convention, it will have to deal with potentially hanging (until timing out)
        // connections and/or RST segments.
        if segment_flags.intersects(TcpFlags::FIN) && !self.fin_received() {
            let fin_seq = seq + wrapping_payload_len;
            // In order to avoid some complexity on our side, we only accept an incoming FIN if its
            // sequence number matches that of the first byte yet to be received (this is similar to
            // what we do for data segments right now).
            if fin_seq == self.ack_to_send {
                self.fin_received = Some(fin_seq);
                // Increase this to also ACK the FIN.
                self.ack_to_send += Wrapping(1);
                enqueue_ack = true;
            } else {
                recv_status_flags |= RecvStatusFlags::INVALID_FIN;
            }
        }
        if enqueue_ack {
            self.enqueue_ack();
            // We check this here because if a valid payload has been received, then we must have
            // set enqueue_ack = true earlier.
            if payload_len > 0 {
                buf[..payload_len].copy_from_slice(s.payload());
                // The unwrap is safe because payload_len > 0.
                return Ok((
                    Some(NonZeroUsize::new(payload_len).unwrap()),
                    recv_status_flags,
                ));
            }
        }
        Ok((None, recv_status_flags))
    }
pub fn receive_segment < T : NetworkBytes > ( & mut self , s : & TcpSegment < T > , buf : & mut [ u8 ] , now : u64 , ) -> Result < ( Option < NonZeroUsize > , RecvStatusFlags ) , RecvError > { if self . rst_pending ( ) || self . is_reset ( ) { return Err ( RecvError :: ConnectionReset ) ; } // TODO: The following logic fully makes sense only for a passive open (which is what we // currently support). Things must change a bit if/when we also implement active opens. let segment_flags = s . flags_after_ns ( ) ; if segment_flags . intersects ( TcpFlags :: RST ) { let seq = Wrapping ( s . sequence_number ( ) ) ; // We accept the RST only if it carries an in-window sequence number. // TODO: If/when we support active opens, we'll also have to accept RST/SYN segments, // which must acknowledge our SYN to be valid. if seq_at_or_after ( seq , self . ack_to_send ) && seq_after ( self . local_rwnd_edge , seq ) { self . set_flags ( ConnStatusFlags :: RESET ) ; return Ok ( ( None , RecvStatusFlags :: RESET_RECEIVED ) ) ; } else { return Ok ( ( None , RecvStatusFlags :: INVALID_RST ) ) ; } } let payload_len = s . len ( ) - s . header_len ( ) ; let mut recv_status_flags = RecvStatusFlags :: empty ( ) ; if ! self . synack_sent ( ) { // We received another segment before getting the chance to send a SYNACK. It's either // a retransmitted SYN, or something that does not make sense. if self . is_same_syn ( s ) { return Ok ( ( None , recv_status_flags ) ) ; } else { return self . reset_for_segment_helper ( s , RecvStatusFlags :: INVALID_SEGMENT ) ; } } else if ! self . is_established ( ) { // So at this point we've sent at least one SYNACK, but the connection is not // ESTABLISHED yet. We only accept SYN retransmissions and ACKs. I'm not sure that // it's completely forbidden to sent an ACK + data in response to a SYNACK, so we don't // complain about non-pure ACKs (or even data + ACK + FIN segments). if self . is_same_syn ( s ) { // Maybe our previous SYNACK got lost or smt, so clear SYN_ACK_SENT to resend it. self . clear_flags ( ConnStatusFlags :: SYNACK_SENT ) ; return Ok ( ( None , recv_status_flags ) ) ; } else if segment_flags . intersects ( TcpFlags :: SYN ) { // So we basically freak out over SYN segments which are not valid SYN // retransmission. return self . reset_for_segment_helper ( s , RecvStatusFlags :: INVALID_SEGMENT ) ; } } else { // Reaching this branch means the connection is ESTABLISHED. The only thing we want to // do right now is reset if we get segments which carry the SYN flag, because they are // obviously invalid, and something must be really wrong. // TODO: Is it an overreaction to reset here? if s . flags_after_ns ( ) . intersects ( TcpFlags :: SYN ) { return self . reset_for_segment_helper ( s , RecvStatusFlags :: INVALID_SEGMENT ) ; } } // The ACK number can only be valid when ACK flag is set. The following logic applies to // pretty much all connection states which can reach this point. if segment_flags . intersects ( TcpFlags :: ACK ) { let ack = Wrapping ( s . ack_number ( ) ) ; if seq_at_or_after ( ack , self . highest_ack_received ) && seq_at_or_after ( self . first_not_sent , ack ) { // This is a valid ACK. Reset rto_count, since this means the other side is still // alive and kicking (or ACking). self . rto_count = 0 ; if ack == self . highest_ack_received && ack != self . first_not_sent { if ! self . is_established ( ) { // Just kidding, a DUPACK is not valid before the connection is ESTABLISHED. return self . reset_for_segment_helper ( s , RecvStatusFlags :: INVALID_ACK ) ; } // Duplicate ACKs can only increase in sequence number, so there's no need // to check if this one is older than self.dup_ack. self . dup_ack = true ; recv_status_flags |= RecvStatusFlags :: DUP_ACK ; } else { // We're making progress. We should also reset rto_start in this case. self . highest_ack_received = ack ; self . rto_start = now ; if ! self . is_established ( ) && self . synack_sent ( ) { // The connection becomes ESTABLISHED. self . set_flags ( ConnStatusFlags :: ESTABLISHED ) ; } if self . fin_sent ( ) && ack == self . first_not_sent { self . set_flags ( ConnStatusFlags :: FIN_ACKED ) ; } } // Look for remote remote rwnd updates. if self . is_established ( ) { let edge = self . compute_remote_rwnd_edge ( ack , s . window_size ( ) ) ; if seq_after ( edge , self . remote_rwnd_edge ) { self . remote_rwnd_edge = edge ; } else if edge != self . remote_rwnd_edge { // The right edge of the remote receive window has been moved to the left, // or has been set to an invalid value. Both cases represent erroneous TCP // behaviour. recv_status_flags |= RecvStatusFlags :: REMOTE_RWND_EDGE ; } } } else { recv_status_flags |= RecvStatusFlags :: INVALID_ACK ; if ! self . is_established ( ) { // Reset the connection if we receive an invalid ACK before reaching the // ESTABLISHED state. return self . reset_for_segment_helper ( s , recv_status_flags ) ; } } } // We start looking at the payload and/or FIN next. This makes sense only if the // connection is established. if ! self . is_established ( ) { return Ok ( ( None , recv_status_flags ) ) ; } let seq = Wrapping ( s . sequence_number ( ) ) ; let wrapping_payload_len = Wrapping ( payload_len as u32 ) ; if payload_len > buf . len ( ) { return Err ( RecvError :: BufferTooSmall ) ; } let mut enqueue_ack = if payload_len > 0 { let data_end_seq = seq + wrapping_payload_len ; if let Some ( fin_seq ) = self . fin_received { if ! seq_at_or_after ( fin_seq , data_end_seq ) { // TODO: This is a strange situation, because the other endpoint is sending data // after it initially closed its half of the connection. We simply ignore the // segment for now. return Ok ( ( None , recv_status_flags | RecvStatusFlags :: DATA_BEYOND_FIN ) ) ; } } if ! seq_at_or_after ( self . local_rwnd_edge , data_end_seq ) { // TODO: This is another strange (and potentially dangerous) situation, because // either we or the other endpoint broke receive window semantics. We simply ignore // the segment for now. return Ok ( ( None , recv_status_flags | RecvStatusFlags :: SEGMENT_BEYOND_RWND , ) ) ; } // We currently assume segments are seldom lost or reordered, and only accept those with // the exact next sequence number we're waiting for. if seq != self . ack_to_send { // TODO: Maybe we should enqueue multiple ACKs here (after making such a thing // possible in the first place), just so we're more likely to trigger a // retransmission. self . enqueue_ack ( ) ; return Ok ( ( None , recv_status_flags | RecvStatusFlags :: UNEXPECTED_SEQ ) ) ; } self . ack_to_send = data_end_seq ; true } else { false } ; // We assume the sequence number of the FIN does not change via conflicting FIN carrying // segments (as it should be the case during TCP normal operation). It the other endpoint // breaks this convention, it will have to deal with potentially hanging (until timing out) // connections and/or RST segments. if segment_flags . intersects ( TcpFlags :: FIN ) && ! self . fin_received ( ) { let fin_seq = seq + wrapping_payload_len ; // In order to avoid some complexity on our side, we only accept an incoming FIN if its // sequence number matches that of the first byte yet to be received (this is similar to // what we do for data segments right now). if fin_seq == self . ack_to_send { self . fin_received = Some ( fin_seq ) ; // Increase this to also ACK the FIN. self . ack_to_send += Wrapping ( 1 ) ; enqueue_ack = true ; } else { recv_status_flags |= RecvStatusFlags :: INVALID_FIN ; } } if enqueue_ack { self . enqueue_ack ( ) ; // We check this here because if a valid payload has been received, then we must have // set enqueue_ack = true earlier. if payload_len > 0 { buf [ .. payload_len ] . copy_from_slice ( s . payload ( ) ) ; // The unwrap is safe because payload_len > 0. return Ok ( ( Some ( NonZeroUsize :: new ( payload_len ) . unwrap ( ) ) , recv_status_flags , ) ) ; } } Ok ( ( None , recv_status_flags ) ) }
Handles an incoming segment.
Handles an incoming segment .
&mut self
s
&TcpSegment<T>
buf
&mut [u8]
now
u64
&mut self
s
&TcpSegment<T>
buf
&mut [u8]
now
u64