pub struct Segment<P> { /* private fields */ }
Expand description
A TCP segment.
Implementations§
Source§impl<P: Payload> Segment<P>
impl<P: Payload> Segment<P>
Sourcepub fn new(header: SegmentHeader, data: P) -> (Self, usize)
pub fn new(header: SegmentHeader, data: P) -> (Self, usize)
Creates a new segment with the provided header and 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 header(&self) -> &SegmentHeader
pub fn header(&self) -> &SegmentHeader
Returns a borrow of the segment’s header.
Sourcepub fn into_parts(self) -> (SegmentHeader, P)
pub fn into_parts(self) -> (SegmentHeader, P)
Destructures self into its inner parts: The segment header and the data payload.
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_empty(header: SegmentHeader) -> Self
pub fn new_empty(header: SegmentHeader) -> Self
Creates a segment with 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 ack_with_options(
seq: SeqNum,
ack: SeqNum,
wnd: UnscaledWindowSize,
options: Options,
) -> Self
pub fn ack_with_options( seq: SeqNum, ack: SeqNum, wnd: UnscaledWindowSize, options: Options, ) -> Self
Creates an ACK segment with options.
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: 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,
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more