Difference between revisions of "TTCPSendBuffer"

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:47, 30 May 2018

Return to Unit TCP


Description


To be documented

Class definitions



TTCPSendBuffer = class(TSocketBuffer)

constructor Create(ASocket:TTransportSocket);  
destructor Destroy; override;  
private
FFirst:PTCPSegment; Pointer to First Segment
FLast:PTCPSegment; Pointer to Last Segment
 
function AddSegment(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 Local (ISS)
NextSequence:LongWord; Next Sequence number to Send (SND.NXT
LastSequence:LongWord; Last Sequence number in Buffer
LastAcknowledge:LongWord; Last Acknowledged number from Remote (SND.UNA)

Note: LastAcknowledge is the NextSequence that Remote expects to Receive or the first Unacknowledged Sequence number. If LastAcknowledge equals NextSequence all segments have been Acknowledged LastSequence is the last sequence in our buffer to send. If NextSequence equals LastSequence there is no more data to send.

 
UrgentPointer:LongWord; (SND.UP)
 
MaxSeg:Word; Remote Max Segment Size (Learned from Remote)
 
WindowSize:LongWord; Remote Window Size (SND.WND)
WindowScale:Byte; Remote Window Scale
WindowTimeout:Int64; Timeout for probing small/zero Window
 
CongestionWindow:Word; Slow Start Window Size
 
SynSequence:LongWord; Sequence number of our SYN
FinSequence:LongWord; Sequence number of our FIN
 
WindowSequence:LongWord; Sequence number of last Window update (SND.WL1)
WindowAcknowledge:LongWord; Acknowledge number of last Window update (SND.WL2)
 
NoPush:Boolean; Disable Push on final segment
NoSack:Boolean; Selective Ack not in use
NoNagle:Boolean; Nagle not in use
 
VjSa:LongWord; VJ's alg, standard average
VjSd:LongWord; VJ's alg, standard deviation
VjLast:LongWord; VJ's alg, last transmit time
 
function CheckIdle:Boolean;  
 
function SynAcknowledged:Boolean;  
function FinAcknowledged:Boolean;  
 
function TestAcknowledge(AAcknowledge:LongWord):Boolean;  
function CheckAcknowledge(AAcknowledge:LongWord):Boolean;  
function ValidateAcknowledge(AAcknowledge:LongWord):Boolean;  
 
function WriteData(var ABuffer; ASize,AFlags:Integer):Boolean;  
 
function Finish:Boolean;  
function Synchronize:Boolean;  
 
function ReadSegment(var ASequence:LongWord; var AUrgent:Word; var AFlags:Byte; var AData:Pointer; var ASize:Word; AForce:Boolean):Boolean;  
function AcknowledgeSegments(ASequence,AAcknowledge:LongWord; AWindow:Word):Boolean;  
 
function TimestampSegment(AOptions:Pointer; var AOffset:Word):Boolean;  
function SelectiveAckSegments(AOptions:Pointer; var AOffset:Word; ASize:Byte):Boolean;  


Function declarations



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


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


function TTCPSendBuffer.AddSegment(ASequence:LongWord; AFlags:Byte; ASize:Word):PTCPSegment;
Description: Adds a new Segment as the last segment in the list
Sequence Sequence is the start sequence
Size Size can be zero

Size should not include the SYN and FIN sequence


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


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


procedure TTCPSendBuffer.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 TTCPSendBuffer.CheckIdle:Boolean;
Description: Check if all data in the send buffer has been sent and acknowledged
Note None documented


function TTCPSendBuffer.SynAcknowledged:Boolean;
Description: Test if a SYN has been sent and if it has been ACKed
Note None documented


function TTCPSendBuffer.FinAcknowledged:Boolean;
Description: Test if a FIN has been sent and if it has been ACKed
Note None documented


function TTCPSendBuffer.TestAcknowledge(AAcknowledge:LongWord):Boolean;
Description: Tests an Acknowledge for invalidity
Note If SEG.ACK =< ISS, or SEG.ACK > SND.NXT then the ACK is unacceptable

Only ever used when Socket is in SYN_SENT state


function TTCPSendBuffer.CheckAcknowledge(AAcknowledge:LongWord):Boolean;
Description: Checks an Acknowledge for validity
Note If SND.UNA =< SEG.ACK =< SND.NXT then the ACK is acceptable

Only ever used when Socket is in SYN_REC state


function TTCPSendBuffer.ValidateAcknowledge(AAcknowledge:LongWord):Boolean;
Description: Checks an Acknowledge for validity
Note If the ACK acks something not yet sent (SEG.ACK > SND.NXT) then send an ACK

Used when Socket is in any of the Synchronized states


function TTCPSendBuffer.WriteData(var ABuffer; ASize,AFlags:Integer):Boolean;
Description: Used by Send/SendTo to Write data into the buffer ready for Sending
Flags Flags is for MSG_PEEK and MSG_OOB when applicable
Note Data that will not fit in the Buffer is simply discarded

Send coalescing is handled here by checking Last segment
Push flag is set on the last written segment of user data

Socket Timing Whenever data is written to the buffer a notification is sent to the socket thread to check the socket immediately. This ensures that the segment is sent immediately if acceptable or otherwise will be sent when an acknowledge is received from the remote due to the Nagle algorithm.


function TTCPSendBuffer.Finish:Boolean;
Description: To be documented
Socket Timing When the FIN segment is written to the buffer a notification is sent to the socket thread to check the socket immediately. This ensures that the segment will be sent to the remote either immediately or after the Nagle delay.


function TTCPSendBuffer.Synchronize:Boolean;
Description: To be documented
Socket Timing When the SYN segment is written to the buffer a notification is sent to the socket thread to check the socket immediately. This ensures that the segment will be sent to the remote immediately.


function TTCPSendBuffer.ReadSegment(var ASequence:LongWord; var AUrgent:Word; var AFlags:Byte; var AData:Pointer; var ASize:Word; AForce:Boolean):Boolean;
Description: Used by Socket to Read segments to be (re)sent from queue
Note Nagle Algorithm and Retry Timeouts are handled here
Socket Timing For each sent segment a notification is scheduled for the socket thread to check the socket in TCP_RETRY_TIMEOUT[Segment.Count] milliseconds. This is to ensure that the segment is retried if not acknowledged by that time.



For each sent segment that has a following segment a notification is sent to the socket thread to check the socket immediately. This ensures that all acceptable segments are sent immediately.

For each retried segment a notification is also scheduled for the socket thread to check the socket in TCP_RETRY_TIMEOUT[Segment.Count] milliseconds which will be the next retry time if still not acknowledged.

If the remote Window is not large enough to send the next segment then a notification is scheduled for the socket thread to check the socket in TCP_WINDOW_TIMEOUT milliseconds to ensure that a window probe is sent at the appropriate time.


function TTCPSendBuffer.AcknowledgeSegments(ASequence,AAcknowledge:LongWord; AWindow:Word):Boolean;
Description: Used by Socket to Acknowledge segments that have been sent and update the Window
Note Sequence, Acknowledge and Window are from the received Segment
Socket Timing For each acknowledged segment a notification is sent to the socket thread to check the socket immediately. This is to ensure that segments waiting to be sent due to the Nagle algorithm are sent on receipt of an acknowledge.


function TTCPSendBuffer.TimestampSegment(AOptions:Pointer; var AOffset:Word):Boolean;
Description: Used by Socket to Timestamp (RTT) segments that have been sent
Offset Offset points to the point to extract the timestamp option


function TTCPSendBuffer.SelectiveAckSegments(AOptions:Pointer; var AOffset:Word; ASize:Byte):Boolean;
Description: Used by Socket to Selective Ack segments that have been sent
Offset Offset points to the point to start extracting SACKS
Size Size includes the Option and Size


Return to Unit Reference