pub struct Segment<P> {
pub header: SegmentHeader,
pub data: P,
}
Expand description
A TCP segment.
Fields§
§header: SegmentHeader
The non-payload information of the segment.
data: P
The data carried by the segment.
It is guaranteed that data.len() plus the length of the control flag (SYN or FIN) is <= MAX_PAYLOAD_AND_CONTROL_LEN
Implementations§
Source§impl<P: Payload> Segment<P>
impl<P: Payload> Segment<P>
Sourcepub fn with_data_options(
seq: SeqNum,
ack: Option<SeqNum>,
control: Option<Control>,
wnd: UnscaledWindowSize,
data: P,
options: Options,
) -> (Self, usize)
pub fn with_data_options( seq: SeqNum, ack: Option<SeqNum>, control: Option<Control>, wnd: UnscaledWindowSize, data: P, options: Options, ) -> (Self, usize)
Creates a new segment with data and options.
Returns the segment along with how many bytes were removed to make sure
sequence numbers don’t wrap around, i.e., seq.before(seq + seg.len())
.
Sourcepub fn with_data(
seq: SeqNum,
ack: Option<SeqNum>,
control: Option<Control>,
wnd: UnscaledWindowSize,
data: P,
) -> (Self, usize)
pub fn with_data( seq: SeqNum, ack: Option<SeqNum>, control: Option<Control>, wnd: UnscaledWindowSize, data: P, ) -> (Self, usize)
Creates a new segment with data.
Returns the segment along with how many bytes were removed to make sure
sequence numbers don’t wrap around, i.e., seq.before(seq + seg.len())
.
Sourcepub fn map_payload<R, F: FnOnce(P) -> R>(self, f: F) -> Segment<R>
pub fn map_payload<R, F: FnOnce(P) -> R>(self, f: F) -> Segment<R>
Maps the payload in the segment with f
.
Sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Returns the length of the segment in sequence number space.
Per RFC 793 (https://tools.ietf.org/html/rfc793#page-25): SEG.LEN = the number of octets occupied by the data in the segment (counting SYN and FIN)
Sourcepub fn overlap(self, rnxt: SeqNum, rwnd: WindowSize) -> Option<Segment<P>>
pub fn overlap(self, rnxt: SeqNum, rwnd: WindowSize) -> Option<Segment<P>>
Returns the part of the incoming segment within the receive window.
Sourcepub fn new(
seq: SeqNum,
ack: Option<SeqNum>,
control: Option<Control>,
wnd: UnscaledWindowSize,
) -> Self
pub fn new( seq: SeqNum, ack: Option<SeqNum>, control: Option<Control>, wnd: UnscaledWindowSize, ) -> Self
Creates a segment with no data.
Sourcepub fn with_options(
seq: SeqNum,
ack: Option<SeqNum>,
control: Option<Control>,
wnd: UnscaledWindowSize,
options: Options,
) -> Self
pub fn with_options( seq: SeqNum, ack: Option<SeqNum>, control: Option<Control>, wnd: UnscaledWindowSize, options: Options, ) -> Self
Creates a new segment with options but no data.
Sourcepub fn ack(seq: SeqNum, ack: SeqNum, wnd: UnscaledWindowSize) -> Self
pub fn ack(seq: SeqNum, ack: SeqNum, wnd: UnscaledWindowSize) -> Self
Creates an ACK segment.
Sourcepub fn syn(seq: SeqNum, wnd: UnscaledWindowSize, options: Options) -> Self
pub fn syn(seq: SeqNum, wnd: UnscaledWindowSize, options: Options) -> Self
Creates a SYN segment.
Trait Implementations§
impl<P: Copy> Copy for Segment<P>
impl<P: Eq> Eq for Segment<P>
impl<P> StructuralPartialEq for Segment<P>
Auto Trait Implementations§
impl<P> Freeze for Segment<P>where
P: Freeze,
impl<P> RefUnwindSafe for Segment<P>where
P: RefUnwindSafe,
impl<P> Send for Segment<P>where
P: Send,
impl<P> Sync for Segment<P>where
P: Sync,
impl<P> Unpin for Segment<P>where
P: Unpin,
impl<P> UnwindSafe for Segment<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)