📄 dxsock.pas
字号:
// else begin
// DXString.DoSleepEx(1);
// DXString.ProcessWindowsMessageQueue;
// end;
// End;
// </CODE>
//
// Note
// It is crucial to test this property during any form of a
// loop. A common mistake is to assume this property will return
// the status of the connection when you have not tried to
// receive data from the socket layer. To achieve that
// functionality your loop must occasionally test the readable
// property and the characters to read property.
//
// See Also
// Readable, CharactersToRead, ReceiveLength, ValidSocket, LastCommandStatus,
// WaitForData, DroppedConnection
// =======================================================================================
property Connected:Boolean read IsConnected;
// ============================================================
// This property provides a mechanism for asking the socket
// layer for the total number of bytes existing in its internal
// buffer. When used in conjunction with the readable property
// you are able to detect hot disconnects. As the readable
// property will return a value of true meaning that theres
// something available to be read however the CharactersToRead
// property will return 0.
// ============================================================
property CharactersToRead:Integer read CountWaiting;
// ============================================================
// This property is provided to make your transition from using
// the Borland socket implementation to DXSock much easier. It
// functions exactly like the CharactersToRead property.
//
// Summary
// CharactersToRead, Readable, Connected
// ============================================================
property ReceiveLength:Integer read CountWaiting;
// =============================================================
// This property is used to test if the socket handle is still
// valid. A socket handle is normally invalid if you have not
// established a connection, tried to force accepting a
// connection when there was no connection waiting, or have
// already closed the socket.<B>
//
// </B>
//
// Note
// You will normally use this routine in the case where you plan
// to reuse an existing socket for another connection.
//
// See Also
// Connected, Readable, LastCommandStatus
// =============================================================
property ValidSocket:Boolean read IsValidSocket;
// =============================================================
// This property is used to test if the last read routine failed
// due to the lack of data present at the socket layer.
//
// See Also
// LastCommandStatus, Connected, ValidSocket
// =============================================================
property LastReadTimeout:Boolean read fReadTimeout;
// =======================================================
// This property is used to inquire the status of the last
// socket layer command.
//
//
//
//
//
// See Also
// GetErrorStr, GetErrorDesc, LastReadTimeout
// =======================================================
property LastCommandStatus:Integer read FErrStatus write FErrStatus;
// =============================================================
// Internally all output routines use a chunking technique, this
// property allows you to specify how much data per output call
// to send to the actual socket layer buffer.
//
//
//
// bsfRealSmall=128
//
// bsfSmall=256
//
// bsfNormal=512
//
// bsfBigger2048
//
// bsfBiggest=4096
//
// else use the gloabl constant TDXHugeSize
//
// See Also
// TooManyCharacters
// =============================================================
property OutputBufferSize:TDXBlockSizeFlags read fBlockSizeFlags
write SetfBlockSizeFlags;
// =========================================================
// This property is used to assess the threshold to avoid
// hacker-overrun attacks. Default is 2048 bytes, which is
// usually more than enough for any protocol implementation.
// This property is used by all routines that read from the
// socket layer checking for a specified delimiter.
//
// See Also
// ReadLn, OutputBufferSize
// =========================================================
property TooManyCharacters:Integer read fTooManyCharacters
write fTooManyCharacters;
// =======================================================
// This property provides a mechanism to query the current
// instance of TDXSock if the instance is using UDP.<B>
//
// </B>
//
// Note
// Provided for internal usage for the different threading
// models, but documented since the property is public.
// =======================================================
property IsUDPMode:Boolean read fbIsUDP
write fbIsUDP;
// =========================================================
// This property provides a mechanism to query the current
// instance of TDXSock if the instance is using socket layer
// Keep-Alive packets. (enabled by default in DXSock)
// =========================================================
property IsKeepAliveMode:Boolean read fbIsKeepAlive write fbIsKeepAlive;
// =========================================================
// This property provides a mechanism that returns the IP
// address of the client that is currently connected to this
// instance of TDXSock.
//
// See Also
// PeerPort, LocalIPAddress
// =========================================================
property PeerIPAddress:string read GlobalPeerIPAddress
write GlobalPeerIPAddress;
// ===========================================================
// This property provides a mechanism that returns the port of
// the client that is currently connected to this instance of
// TDXSock.
//
// See Also
// PeerIPAddress, LocalPort
// ===========================================================
property PeerPort:Integer read GlobalPeerPort
write GlobalPeerPort;
// ======================================================
// This property provides a mechanism that returns the IP
// address the client is currently connected to for this
// instance of TDXSock.
//
// See Also
// LocalPort, BindTo, PeerIPAddress
// ======================================================
property LocalIPAddress:string read GetLocalIPAddr;
// ============================================================
// This property provides a mechanism that returns the port the
// client is currently connected to for this instance of
// TDXSock.
//
// See Also
// LocalIPAddress, PeerPort
// ============================================================
property LocalPort:Integer read GetLocalPort;
// ============================================================
// This property is used to inquire if the socket layer has
// something available to be checked for. It can be a pending
// disconnect notification, or an unread packets.
//
// Note
// A common mistake is to test this property very often in a
// loop. You should only use this in conjunction with the
// CharactersToRead property to detect a hot disconnect. As the
// readable property will return a value of true meaning that
// theres something available to be read however the
// CharactersToRead property will return 0.
//
// See Also
// Connected, Writable
// ============================================================
property Readable:Boolean read IsReadable;
// =======================================================
// This property is used to inquire if the socket layer is
// capable of sending data.
//
//
//
// Note
// We have never really found a use for this function.
//
// See Also
// Readable
// =======================================================
property Writable:Boolean read IsWritable;
// =============================================================
// This property provides a mechanism that will inform you of
// the release date of the source code being used for your
// server. You can use this internally for your development team
// for when reporting problems to the support staff.
// =============================================================
property ReleaseDate:string read GetReleaseDate
write SetReleaseDate;
// =============================================================
// This property provides a mechanism for on-the-fly compression
// \or basic encryption. When this event is implemented in your
// server, it will be automatically fired before every socket
// layer write - allowing you to modify the inbound data and
// return it as outbound data. It then is automatically fired
// after the write has occurred so you can destroy the temporary
// pointer used for the outbound data. If you have implemented
// this functionality for your server, youll need to manually
// call the FilterRead function after every read. The reason it
// cannot automatically call the FilterRead routine is due to
// the fact some of the read routines in the suite accept
// pointers as parameters - thus it would create a memory leak.
// =============================================================
property OnFilter:TDXFilterCallBack read feOnFilter
write feOnFilter;
{$IFDEF TLS_EDITION}
property OnReadFilter:TDXFilterCallBack read feOnReadFilter
write feOnReadFilter;
{$ENDIF}
property OnWriteBuffer : TDXWriteBufferCallback read feOnWriteBuffer write feOnWriteBuffer;
property OnReadBuffer : TDXReadBufferCallback read feOnReadBuffer write feOnReadBuffer;
end;
implementation
uses
{$IFNDEF LINUX}
Windows,
{$ENDIF}
SysUtils;
function TDXSock.GetReleaseDate:string;
begin
Result:=BPDX_RELEASE_DATE;
end;
procedure TDXSock.SetReleaseDate (value:string) ;
begin
// Absorb!
end;
constructor TDXSock.Create (AOwner:TComponent) ;
begin
inherited Create (AOwner) ;// RC2
FReadTimeout:=False;
System.GetMem(FPeekBuffer,PeekBufferSize);
LastFBlockSizeFlags:=bsfZero;
SetFBlockSizeFlags (bsfHuge) ;
if not SocketLayerLoaded then
ShowMessageWindow ('Fatal Socket Error','(WSAStartup) '+GetErrorStr) ;
fTooManyCharacters:=2048;
Sock:=INVALID_SOCKET;
fbIsUDP:=False;
fbIsKeepAlive:=False;
fbClientMode:=False;
FUseBlocking:=True;
GlobalPeerPort:=0;
GlobalPeerIPAddress:='';
VarConstSizeofTSockAddrIn:=ConstSizeofTSockAddrIn;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -