Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
prog:lazarus:a_etudier [26/04/2021 20:03]
thierry créée
prog:lazarus:a_etudier [27/04/2021 17:16] (Version actuelle)
thierry [TLockedEvent = specialize TThreadedData<TNotifyEvent>;]
Ligne 8: Ligne 8:
   end;   end;
  
 +</​code>​
 +===== TLockedEvent = specialize TThreadedData<​TNotifyEvent>;​ =====
 +
 +<code delphi LazWebsockets\src\wsstream.pas>​
 +  TLockedEvent = specialize TThreadedData<​TNotifyEvent>;​
 +...
 +    function GetOnClose: TNotifyEvent;​
 +    procedure SetOnClose(AValue:​ TNotifyEvent)
 +...
 +    property OnClose: TNotifyEvent read GetOnClose write SetOnClose;
 +...
 +function TWebsocketCommunicator.GetOnClose:​ TNotifyEvent;​
 +begin
 +  try
 +    Result := FOnClose.Lock^;​
 +  finally
 +    FOnClose.Unlock;​
 +  end;
 +end;
 +
 +procedure TWebsocketCommunicator.SetOnClose(AValue:​ TNotifyEvent);​
 +begin
 +  try
 +    FOnClose.Lock^ := AValue;
 +  finally
 +    FOnClose.Unlock;​
 +  end;
 +end;
 +...
 +constructor TWebsocketCommunicator.Create(AStream:​ TLockedSocketStream;​
 +  AMaskMessage:​ boolean; AssumeMaskedMessages:​ boolean);
 +begin
 +...
 +  FOnClose.Init(nil);​
 +...
 +end;
 +
 +destructor TWebsocketCommunicator.Destroy;​
 +begin
 +...
 +  FOnClose.Done;​
 +  inherited Destroy;
 +end;
 +
 +procedure TWebsocketCommunicator.Close(ForceClose:​ boolean);
 +var
 +  OnCloseEvent:​ TNotifyEvent;​
 +begin
 +...
 +  OnCloseEvent := OnClose;
 +  if Assigned(OnCloseEvent) then
 +    OnCloseEvent(Self);​
 +...
 +end;
 +</​code>​
 +
 +Avec...
 +<code delphi LazWebsockets\src\wsutils.pas>​
 +{ TThreadedData }
 +
 +  generic TThreadedData<​T>​ = record
 +  public type PT = ^T;
 +  private
 +    FData: T;
 +    FLock: TRTLCriticalSection;​
 +  public
 +    procedure Init(const AValue: T);
 +    procedure Done;
 +    function Lock: PT;
 +    procedure Unlock;
 +  end;              ​
 </​code>​ </​code>​