Difference between revisions of "TTCPRecvBuffer"

From Ultibo.org
Jump to: navigation, search
(Created page with "Return to Unit TCP __TOC__ === Description === ---- ''To be documented'' === Class definitions === ---- <div class="toccolours mw-collapsible mw-collapsed"...")
(No difference)

Revision as of 01:50, 30 May 2018

Return to Unit TCP


Description


To be documented

Class definitions



TTCPRecvBuffer = class(TSocketBuffer)

constructor Create(ASocket:TTransportSocket);  
destructor Destroy; override;  
private
FUrgent:LongWord; Number of OOB bytes readable from Buffer
FAvailable:LongWord; Number of bytes readable from Buffer
 
FFirst:PTCPSegment; Pointer to First Segment
FLast:PTCPSegment; Pointer to Last Segment
 
function DelayOverride(ASegment:PTCPSegment):Boolean;  
 
function GetSegment(ASequence:LongWord; ALength:Word):PTCPSegment;  
function GetPrevious(ASequence:LongWord; ALength:Word):PTCPSegment;  
function GetOverlapped(ASequence:LongWord; ALength:Word):PTCPSegment;  
 
function AddSegment(APrev:PTCPSegment; ASequence:LongWord; AFlags:Byte; ASize:Word):PTCPSegment;  
function RemoveSegment(ASegment:PTCPSegment):Boolean;  
procedure FlushSegments(All:Boolean);  
protected
procedure SetSize(ASize:LongWord); override;  
public
StartSequence:LongWord; Initial Sequence number of Remote (IRS)
NextSequence:LongWord; Next Sequence number to Receive (RCV.NXT)
LastSequence:LongWord; Last Sequence number in Buffer (Including Unacknowledged data)
LastAcknowledge:LongWord; Last Acknowledged number to Remote

Note: NextSequence is the next byte we expect to Receive from Remote. LastAcknowledge will be the first Unacknowledged Seqeunce number of the Remote. LastSequence is the last sequence we have received from the Remote. If NextSequence equals LastSequence and LastAcknowledge equals NextSequence all segments have been Acknowledged.

 
UrgentPointer:LongWord; (RCV.UP)
 
MaxSeg:Word; Local Max Segment Size
 
WindowSize:LongWord; Local Window Size (RCV.WND)
WindowScale:Byte; Local Window Scale
LastWindow:LongWord; Last Window value sent to Remote
 
SynSequence:LongWord; Sequence number of remote SYN
FinSequence:LongWord; Sequence number of remote FIN
 
NoSack:Boolean; Selective Ack not in use
 
function CheckIdle:Boolean;  
 
function GetUrgent:LongWord;  
function GetAvailable:LongWord;  
 
function SynReceived:Boolean;  
function FinReceived:Boolean;  
 
function CheckSequence(ASequence:LongWord; ASize:Word):Boolean;  
 
function ReadData(var ABuffer; var ASize:Integer; AFlags:Integer):Boolean;  
 
function WriteSegment(ASequence:LongWord; AUrgent:Word; AFlags:Byte; AData:Pointer; ASize:Word):Boolean;  
function AcknowledgeSegments(var AAcknowledge:LongWord; var AWindow:Word; AForce:Boolean):Boolean;  
 
function TimestampSegment(AOptions:Pointer; var AOffset:Word):Boolean;  
function SelectiveAckSegments(AOptions:Pointer; var AOffset:Word):Boolean;  


Function declarations



constructor TTCPRecvBuffer.Create;
Description: To be documented
Note None documented


destructor TTCPRecvBuffer.Destroy;
Description: To be documented
Note None documented


function TTCPRecvBuffer.DelayOverride(ASegment:PTCPSegment):Boolean;
Description: Checks if this segment can override delayed ack because it has an in sequence segment following it
Note Delayed ack must send an ack at least every two segments


function TTCPRecvBuffer.GetSegment(ASequence:LongWord; ALength:Word):PTCPSegment;
Description: Returns the first Segment that contains ALL of the passed Sequence
Sequence Sequence is the start sequence
Length Length includes the control bits
Matching Conditions ------|

1 Match . |--| . First <= Seqeuence and Last >= Sequence + Length
2 Match |------| First <= Seqeuence and Last >= Sequence + Length
3 No Match |----------|
4 No Match . |------|
5 No Match |------| .
6 No Match |----| .
7 No Match . |----|


function TTCPRecvBuffer.GetPrevious(ASequence:LongWord; ALength:Word):PTCPSegment;
Description: Finds the first Segment that is AFTER the passed Sequence and returns the previous Segment
Sequence Sequence is the start sequence
Length Length includes the control bits
Note If no Segment is after the passed Sequence returns the last Segment
Matching Conditions ------|

1 Match |--| . Sequence + Length <= First
2 Match |--| . . Sequence + Length <= First
3 No Match |-------| .
4 No Match |-------|
5 No Match . |-------|
6 No Match . |-------|


function TTCPRecvBuffer.GetOverlapped(ASequence:LongWord; ALength:Word):PTCPSegment;
Description: Returns the first Segment that overlaps ANY of the passed Sequence
Sequence Sequence is the start sequence
Length Length includes the control bits
Matching Conditions ------|

1 Match |----------| Seqeuence <= First and Sequence + Length >= Last
2 Match |------| . Sequence + Length > First and Sequence + Length <= Last
3 Match . |------| Sequence >= First and Sequence < Last

4 No Match . |--| . Matched by GetSegment
5 Match |------| Matched by GetSegment (Also Matches 1)
6 Match |--------| Matched by 1
7 Match |--------| Matched by 1
8 Match |----| . Matched by 2 (Also Matches 3)
9 Match . |----| Matched by 3 (Also Matches 2)
10 No Match . |------|
11 No Match . . |------|


function TTCPRecvBuffer.AddSegment(APrev:PTCPSegment; ASequence:LongWord; AFlags:Byte; ASize:Word):PTCPSegment;
Description: Adds a new Segment after the previous segment or first in the list
Prev Prev is the Previous segment
Sequence Sequence is the start sequence
Size Size can be zero

Size should not include the SYN and FIN sequence


function TTCPRecvBuffer.RemoveSegment(ASegment:PTCPSegment):Boolean;
Description: Removes the passed Segment from the list
Note None documented


procedure TTCPRecvBuffer.FlushSegments(All:Boolean);
Description: Removes Read Segments from the buffer (or All)
Note None documented


procedure TTCPRecvBuffer.SetSize(ASize:LongWord);
Description: To be documented
Size Size cannot be set smaller than the default or existing
Note For TCP setting the size does not clear existing segments


function TTCPRecvBuffer.CheckIdle:Boolean;
Description: Check if all data in the recv buffer has been acknowledged
Note None documented


function TTCPRecvBuffer.GetUrgent:LongWord;
Description: To be documented
Note None documented


function TTCPRecvBuffer.GetAvailable:LongWord;
Description: To be documented
Note None documented


function TTCPRecvBuffer.SynReceived:Boolean;
Description: Checks if a SYN has been received from the Remote
Note None documented


function TTCPRecvBuffer.FinReceived:Boolean;
Description: Checks if a FIN has been received from the Remote
Note None documented


function TTCPRecvBuffer.CheckSequence(ASequence:LongWord; ASize:Word):Boolean;
Description: Checks a Sequence for validity
Note None documented


function TTCPRecvBuffer.ReadData(var ABuffer; var ASize:Integer; AFlags:Integer):Boolean;
Description: Used by Recv/RecvFrom to Read data from the buffer that has been Received
Size Passed Size contains size of Buffer and should return the size of Datagram
Flags Flags is for MSG_PEEK and MSG_OOB when applicable


function TTCPRecvBuffer.WriteSegment(ASequence:LongWord; AUrgent:Word; AFlags:Byte; AData:Pointer; ASize:Word):Boolean;
Description: Used by Socket to Write segments that are received into the queue
Overlap Handling ------|

1 Entire |----------| Seqeuence <= First and Sequence + Length >= Last
2 Left . |------| Sequence > First and Sequence + Length > Last
3 Right |------| . Sequence < First and Sequence + Length < Last
4 Within . |--| . Seqeuence >= First and Sequence + Length <= Last

5 Entire |--------| Matched by 1
6 Entire |--------| Matched by 1
7 Within |----| . Matched by 4
8 Within . |----| Matched by 4
9 Entire |------| Matched by GetSegment (Also Matches 1)

Socket Timing For each received segment a notification is scheduled for the socket thread to check the socket in TCP_ACK_TIMEOUT milliseconds. This is the maximum to before the received segment must be acknowledged, but it may be acknowledged earlier if a segment is sent or if there are earlier received segments to be acknowledged as well.


function TTCPRecvBuffer.AcknowledgeSegments(var AAcknowledge:LongWord; var AWindow:Word; AForce:Boolean):Boolean;
Description: Used by Socket to Acknowledge segments that are received into the queue
Note Delayed Ack is handled here by checking Timeout and following segments
Socket Timing No notifications are sent to or scheduled for the socket thread when checking for received segments to acknowledge. This is because WriteSegment will have scheduled a notification for TCP_ACK_TIMEOUT milliseconds after each segment was received which will ensure they are acknowledged in time.


function TTCPRecvBuffer.TimestampSegment(AOptions:Pointer; var AOffset:Word):Boolean;
Description: Used by Socket to Timestamp (RTT) segments that are received into the queue
Offset Offset points to the point to insert the timestamp option


function TTCPRecvBuffer.SelectiveAckSegments(AOptions:Pointer; var AOffset:Word):Boolean;
Description: To be documented
Note None documented


Return to Unit Reference