Skip to content

Commit

Permalink
Merge pull request #8 from irzyxa/bug/av-on-destroy
Browse files Browse the repository at this point in the history
Fixed AV on destroy when use SSL
  • Loading branch information
mateusvicente100 authored May 24, 2021
2 parents ded89ff + 2c2aba7 commit f088466
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Bird.Socket.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TBirdSocketClient = class(TIdTCPClient)
FOnHeartBeatTimer: TNotifyEvent;
FOnUpgrade: TNotifyEvent;
FSubProtocol: string;
FTaskReadFromWebSocket, FTaskHeartBeat: ITask;
function GenerateWebSocketKey: string;
function IsValidWebSocket: Boolean;
function IsValidHeaders(const AHeaders: TStrings): Boolean;
Expand Down Expand Up @@ -233,7 +234,18 @@ constructor TBirdSocketClient.Create(const AURL: string);
end;

destructor TBirdSocketClient.Destroy;
var
taskArray: array of ITask;
begin
if FTaskReadFromWebSocket <> nil then
taskArray := taskArray + [FTaskReadFromWebSocket];
if FTaskHeartBeat <> nil then
taskArray := taskArray + [FTaskHeartBeat];
if Length(taskArray) > 0 then
TTask.WaitForAll(taskArray);
FTaskReadFromWebSocket := nil;
FTaskHeartBeat := nil;
SetLength(taskArray, 0);
if FAutoCreateHandler and Assigned(FIOHandler) then
FIOHandler.Free;
FInternalLock.Free;
Expand Down Expand Up @@ -396,15 +408,14 @@ class function TBirdSocketClient.New(const AURL: string): TBirdSocketClient;

procedure TBirdSocketClient.ReadFromWebSocket;
var
LTask: ITask;
LOperationCode: Byte;
LSpool: TIdBytes;
begin
if not IsValidWebSocket then
Exit;
if not Connected then
Exit;
LTask := TTask.Run(
FTaskReadFromWebSocket := TTask.Run(
procedure
var
LByte: Byte;
Expand Down Expand Up @@ -532,7 +543,7 @@ procedure TBirdSocketClient.StartHeartBeat;
var
LDateLastNotify: TDateTime;
begin
TThread.CreateAnonymousThread(
FTaskHeartBeat := TTask.Run(
procedure
begin
LDateLastNotify := Now;
Expand All @@ -551,7 +562,7 @@ procedure TBirdSocketClient.StartHeartBeat;
on E:Exception do
HandleException(E);
end;
end).Start;
end);
end;

function TBirdSocketClient.SetBit(const AValue: Cardinal; const AByte: Byte): Cardinal;
Expand Down

0 comments on commit f088466

Please sign in to comment.