12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- unit TypeUnit;
- interface
- uses Windows, Messages, Forms, IdTcpServer, TypeConfig;
- const
- SM_BASE = WM_USER + 200;
- SM_ClientCount = SM_BASE + 1;
- SM_Status = SM_BASE + 2;
- type
- TOperType = (otAdd, otDelete, otModify);
- {客户信息记录}
- TInfoRecd = record
- IP: string;
- User: Integer;
- Action: Integer; {0: Add 1: Delete -1: check}
- end;
- PInfoRecd = ^TInfoRecd;
- {线程信息记录}
- TThrdsRecd = record
- Thread: TIdPeerThread;
- IP : string;
- User : Integer;
- end;
- PThrdsRecd = ^TThrdsRecd;
- TLinkControl = class
- private
- FV0Count: Integer;
- FV1Count: Integer;
- FV2Count: Integer;
- FV0MaxLinks: Integer;
- FV1MaxLinks: Integer;
- FV2MaxLinks: Integer;
- procedure RefreshAppCount;
- public
- procedure AddCount(AType: Integer);
- procedure DeleteCount(AType: Integer);
- function CheckIsFull(AType: Integer): Boolean;
- procedure InitCount;
- property V0MaxLinks: Integer read FV0MaxLinks write FV0MaxLinks;
- property V1MaxLinks: Integer read FV1MaxLinks write FV1MaxLinks;
- property V2MaxLinks: Integer read FV2MaxLinks write FV2MaxLinks;
- end;
- implementation
- { TLinkControl }
- procedure TLinkControl.AddCount(AType: Integer);
- begin
- case AType of
- Flag_Version_0: InterlockedIncrement(FV0Count);
- end;
- RefreshAppCount;
- end;
- function TLinkControl.CheckIsFull(AType: Integer): Boolean;
- begin
- Result := True;
- case AType of
- Flag_Version_0: if FV0Count < FV0MaxLinks then Result := False;
- end;
- end;
- procedure TLinkControl.DeleteCount(AType: Integer);
- begin
- case AType of
- Flag_Version_0: if FV0Count > 0 then InterlockedDecrement(FV0Count);
- end;
- RefreshAppCount;
- end;
- procedure TLinkControl.InitCount;
- begin
- FV0Count := 0;
- RefreshAppCount;
- end;
- procedure TLinkControl.RefreshAppCount;
- var
- wpValue, lpValue: Integer;
- begin
- wpValue := FV0Count;
- wpValue := wpValue shl 16;
- wpValue := wpValue + FV1Count;
- lpValue := FV2Count;
- SendMessage(Application.MainForm.Handle, SM_ClientCount, wpValue, lpValue);
- end;
- end.
|