TTCPProtocol
Return to Unit TCP
Description
To be documented
Class definitions
TTCPProtocol = class(TNetworkProtocol)
constructor Create(AManager:TProtocolManager; const AName:String);
|
|
destructor Destroy; override;
|
|
private
| |
FNextPort:Word;
|
|
FMinBacklog:Integer;
|
|
FMaxBacklog:Integer;
|
|
FReceiveBacklog:Integer;
|
|
function PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
|
|
function SegmentHandler(ASocket:TTCPSocket; ASource,ADest,APacket:Pointer; ASize:Integer):Boolean;
|
|
function ResetHandler(ASocket:TTCPSocket; ASource,ADest,APacket:Pointer; ASize:Integer):Boolean;
|
|
function CloneSocket(ASocket:TTCPSocket; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ALock:Boolean; AState:LongWord):TTCPSocket;
|
|
function GetTCPOptionsSize(ASocket:TTCPSocket; AOptions:Pointer):Word;
|
|
function CreateTCPOptions(ASocket:TTCPSocket; AOptions:Pointer; AFlags:Byte):Boolean;
|
|
function HandleTCPOptions(ASocket:TTCPSocket; AOptions:Pointer; AFlags:Byte):Boolean;
|
|
function InsertTCPOption(ASocket:TTCPSocket; AOptions:Pointer; AOption:Byte):Boolean;
|
|
function ExtractTCPOption(ASocket:TTCPSocket; AOptions:Pointer; AOption:Byte):Boolean;
|
|
function SendReset(ASocket:TTCPSocket):Boolean;
|
|
function SendAcknowledge(ASocket:TTCPSocket):Boolean;
|
|
function SendSegment(ASocket:TTCPSocket; ASource,ADest:Pointer; ASourcePort,ADestPort:Word; ASequence,AAcknowledge:LongWord; AWindow,AUrgent:Word; AFlags:Byte; AOptions,AData:Pointer; ASize:Integer):Integer;
|
|
protected
| |
function OpenPort(ASocket:TProtocolSocket; APort:Word):Boolean; override;
|
|
function ClosePort(ASocket:TProtocolSocket):Boolean; override;
|
|
function FindPort(APort:Word; AWrite,ALock:Boolean):TProtocolPort; override;
|
|
function SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer; override;
|
|
function SelectWait(ASocket:TProtocolSocket; ACode:Integer; ATimeout:LongWord):Integer; override;
|
|
public
| |
function Accept(ASocket:TProtocolSocket; ASockAddr:PSockAddr; AAddrLength:PInteger):TProtocolSocket; override;
|
|
function Bind(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;
|
|
function CloseSocket(ASocket:TProtocolSocket):Integer; override;
|
|
function Connect(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;
|
|
function IoctlSocket(ASocket:TProtocolSocket; ACmd:DWORD; var AArg:u_long):Integer; override;
|
|
function GetPeerName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;
|
|
function GetSockName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;
|
|
function GetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer; override;
|
|
function Listen(ASocket:TProtocolSocket; ABacklog:Integer):Integer; override;
|
|
function Recv(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;
|
|
function RecvFrom(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AFromAddr:TSockAddr; var AFromLength:Integer):Integer; override;
|
|
function Select(ANfds:Integer; AReadfds,AWritefds,AExceptfds:PFDSet; ATimeout:PTimeVal):LongInt; override;
|
|
function Send(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;
|
|
function SendTo(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AToAddr:TSockAddr; AToLength:Integer):Integer; override;
|
|
function SetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer; override;
|
|
function Shutdown(ASocket:TProtocolSocket; AHow:Integer):Integer; override;
|
|
function Socket(AFamily,AStruct,AProtocol:Integer):TProtocolSocket; override;
|
|
function AddTransport(ATransport:TNetworkTransport):Boolean; override;
|
|
function RemoveTransport(ATransport:TNetworkTransport):Boolean; override;
|
|
function FindSocket(AFamily,AStruct,AProtocol:Word; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast,AListen,ALock:Boolean; AState:LongWord):TProtocolSocket; override;
|
|
procedure FlushSockets(All:Boolean); override;
|
|
function StartProtocol:Boolean; override;
|
|
function StopProtocol:Boolean; override;
|
|
function ProcessProtocol:Boolean; override;
|
|
function ProcessSockets:Boolean; override;
|
|
function ProcessSocket(ASocket:TProtocolSocket):Boolean; override;
|
Function declarations
constructor TTCPProtocol.Create(AManager:TProtocolManager; const AName:String);
Note | None documented |
---|
destructor TTCPProtocol.Destroy;
Note | None documented |
---|
function TTCPProtocol.PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Handle | The Handle of the Protocol Transport the packet was received from |
---|---|
Source | The source address of the received packet (Set by Transport) |
Dest | The destination address of the received packet (Set by Transport) |
Packet | The received packet (The complete packet including Transport header) |
Size | The size of the received packet in bytes |
Broadcast | True if the destination address is a broadcast address |
function TTCPProtocol.SegmentHandler(ASocket:TTCPSocket; ASource,ADest,APacket:Pointer; ASize:Integer):Boolean;
Packet | The received packet (The complete packet including Transport header) |
---|---|
Note | Initial validity check on SEQ/ACK and Flags is done here
Caller must hold the Socket lock |
function TTCPProtocol.ResetHandler(ASocket:TTCPSocket; ASource,ADest,APacket:Pointer; ASize:Integer):Boolean;
Packet | The received packet (The complete packet including Transport header) |
---|---|
Note | Must never send a Reset if RST bit is set in Packet
Caller must hold the Socket lock |
function TTCPProtocol.CloneSocket(ASocket:TTCPSocket; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ALock:Boolean; AState:LongWord):TTCPSocket;
Note | New Socket will be SS_UNCONNECTED and TCP_STATE_CLOSED but with the Local and Remote address and port bindings completed (different to a new Socket)
Addresses and Ports are passed in Host order
|
---|
function TTCPProtocol.GetTCPOptionsSize(ASocket:TTCPSocket; AOptions:Pointer):Word;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.CreateTCPOptions(ASocket:TTCPSocket; AOptions:Pointer; AFlags:Byte):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.HandleTCPOptions(ASocket:TTCPSocket; AOptions:Pointer; AFlags:Byte):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.InsertTCPOption(ASocket:TTCPSocket; AOptions:Pointer; AOption:Byte):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.ExtractTCPOption(ASocket:TTCPSocket; AOptions:Pointer; AOption:Byte):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.SendReset(ASocket:TTCPSocket):Boolean;
Note | Not called in response to a bad segment (done by ResetHandler)
May be invoked by calling CloseSocket with a hard close etc
|
---|
function TTCPProtocol.SendAcknowledge(ASocket:TTCPSocket):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.SendSegment(ASocket:TTCPSocket; ASource,ADest:Pointer; ASourcePort,ADestPort:Word; ASequence,AAcknowledge:LongWord; AWindow,AUrgent:Word; AFlags:Byte; AOptions,AData:Pointer; ASize:Integer):Integer;
Note | Both Options and Data can be nil, Size can be zero.
Used instead of SendPacket to allow for the extra parameters needed by TCP
|
---|
function TTCPProtocol.OpenPort(ASocket:TProtocolSocket; APort:Word):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.ClosePort(ASocket:TProtocolSocket):Boolean;
Note | Caller must hold the Socket lock |
---|
function TTCPProtocol.FindPort(APort:Word; AWrite,ALock:Boolean):TProtocolPort;
Port | The port number to find |
---|---|
Write | If True then use the writer lock |
Lock | If True then lock the found entry before returning |
function TTCPProtocol.SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer;
Source | Source is the working set to check |
---|---|
Dest | Dest is the set passed to Select |
function TTCPProtocol.SelectWait(ASocket:TProtocolSocket; ACode:Integer; ATimeout:LongWord):Integer;
Socket | Socket is the single socket to check |
---|---|
Code | Code is the type of check |
Timeout | Timeout is how long to wait |
function TTCPProtocol.Accept(ASocket:TProtocolSocket; ASockAddr:PSockAddr; AAddrLength:PInteger):TProtocolSocket;
Socket | The socket to accept from |
---|---|
SockAddr | The socket address (Network Order) |
AddrLength | The socket address length |
Note | SockAddr is returned in Network order
Caller must hold the Socket lock |
function TTCPProtocol.Bind(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer;
Socket | The socket to bind |
---|---|
SockAddr | The socket address (Network Order) |
AddrLength | The socket address length |
Note | Sets the LocalAddress/Port for future Sends and Receives, Address can be specified as INADDR_ANY which allows Listening or auto assignment. If Port is IPPORT_ANY then a dynamic Port will be assigned.
SockAddr is passed in Network order
|
function TTCPProtocol.CloseSocket(ASocket:TProtocolSocket):Integer;
Socket | The socket to close |
---|---|
Note | Closes and removes the socket, does not perform Linger
Caller must hold the Socket lock |
function TTCPProtocol.Connect(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer;
Socket | The socket to connect |
---|---|
SockAddr | The socket address (Network Order) |
AddrLength | The socket address length |
Note | Sets the RemoteAddress/Port of future Sends and Receives and begins the three way handshake, if Bind has not been called then the LocalAddress/Port will be set appropriately as well based on the route to the RemoteAddress.
SockAddr is passed in Network order
|
function TTCPProtocol.IoctlSocket(ASocket:TProtocolSocket; ACmd:DWORD; var AArg:u_long):Integer;
Socket | The socket to control |
---|---|
Cmd | The socket command |
Arg | The command argument |
Note | Caller must hold the Socket lock |
function TTCPProtocol.GetPeerName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer;
Socket | The socket to get from |
---|---|
SockAddr | The socket address (Network Order) |
AddrLength | The socket address length |
Note | SockAddr is returned in Network order
Caller must hold the Socket lock |
function TTCPProtocol.GetSockName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer;
Socket | The socket to get from |
---|---|
SockAddr | The socket address (Network Order) |
AddrLength | The socket address length |
Note | SockAddr is returned in Network order
Caller must hold the Socket lock |
function TTCPProtocol.GetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer;
Socket | The socket to get the option from |
---|---|
Level | The protocol level for the option |
OptName | The name of the option to get |
OptValue | The value of the option |
OptLength | The length of the option |
Note | Caller must hold the Socket lock |
function TTCPProtocol.Listen(ASocket:TProtocolSocket; ABacklog:Integer):Integer;
Socket | The socket to listen on |
---|---|
Backlog | Queue depth for accepted connections |
Note | Caller must hold the Socket lock |
function TTCPProtocol.Recv(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer;
Socket | The socket to receive from |
---|---|
Buffer | Buffer for received data |
Length | Length of buffer in bytes |
Flags | Protocol specific receive flags |
Note | Caller must hold the Socket lock |
function TTCPProtocol.RecvFrom(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AFromAddr:TSockAddr; var AFromLength:Integer):Integer;
Socket | The socket to receive from |
---|---|
Buffer | Buffer for received data |
Length | Length of buffer in bytes |
Flags | Protocol specific receive flags |
FromAddr | The address the data was received from (Network Order) |
FromLength | The length of the address |
Note | TCP treats RecvFrom as Recv
Caller must hold the Socket lock |
function TTCPProtocol.Send(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer;
Socket | The socket to send to |
---|---|
Buffer | Buffer for data to send |
Length | Length of buffer in bytes |
Flags | Protocol specific send flags |
Note | Caller must hold the Socket lock |
function TTCPProtocol.SendTo(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AToAddr:TSockAddr; AToLength:Integer):Integer;
Socket | The socket to send to |
---|---|
Buffer | Buffer for data to send |
Length | Length of buffer in bytes |
Flags | Protocol specific send flags |
ToAddr | The socket address to send to (Network Order) |
ToLength | The length of the socket address |
Note | TCP treats SendTo as Send
Caller must hold the Socket lock |
function TTCPProtocol.SetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer;
Socket | The socket to set the option for |
---|---|
Level | The protocol level for the option |
OptName | The name of the option to set |
OptValue | The value of the option |
OptLength | The length of the option |
Note | Caller must hold the Socket lock |
function TTCPProtocol.Shutdown(ASocket:TProtocolSocket; AHow:Integer):Integer;
Socket | The socket to shutdown |
---|---|
How | The direction to shutdown the socket |
Note | Shutdown does not result in CloseSocket so Closed must not get set
Caller must hold the Socket lock |
function TTCPProtocol.Socket(AFamily,AStruct,AProtocol:Integer):TProtocolSocket;
Family | Socket address family (eg AF_INET) |
---|---|
Struct | Socket type (eg SOCK_DGRAM) |
Protocol | Socket protocol (eg IPPROTO_UDP) |
Note | When a Socket is created it will be SS_UNCONNECTED and TCP_STATE_CLOSED |
function TTCPProtocol.AddTransport(ATransport:TNetworkTransport):Boolean;
Transport | The transport to add |
---|
function TTCPProtocol.RemoveTransport(ATransport:TNetworkTransport):Boolean;
Transport | The transport to remove |
---|
function TTCPProtocol.FindSocket(AFamily,AStruct,AProtocol:Word; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast,AListen,ALock:Boolean; AState:LongWord):TProtocolSocket;
Family | Socket address family (eg AF_INET) |
---|---|
Struct | Socket type (eg SOCK_DGRAM) |
Protocol | Socket protocol (eg IPPROTO_UDP) |
LocalAddress | Local transport address to match (Host Order) |
RemoteAddress | Remote transport address to match (Host Order) |
LocalPort | Local port to match (Host Order) |
RemotePort | Remote port to match (Host Order) |
Broadcast | If True then match broadcast addresses |
Listen | If True then match only listening sockets |
Lock | If True then lock the found entry before returning |
procedure TTCPProtocol.FlushSockets(All:Boolean);
All | If True flush all sockets, otherwise flush expired sockets. |
---|
function TTCPProtocol.StartProtocol:Boolean;
Note | None documented |
---|
function TTCPProtocol.StopProtocol:Boolean;
Note | None documented |
---|
function TTCPProtocol.ProcessProtocol:Boolean;
Note | None documented |
---|
function TTCPProtocol.ProcessSockets:Boolean;
Note | None documented |
---|
function TTCPProtocol.ProcessSocket(ASocket:TProtocolSocket):Boolean;
Note | None documented |
---|
Return to Unit Reference