[fpc-pascal] How to close TInetServer without except?

silvioprog silvioprog at gmail.com
Fri May 3 18:48:07 CEST 2013


2013/5/3 Zaher Dirkey <parmaja at gmail.com>

>
> On Fri, May 3, 2013 at 6:57 PM, silvioprog <silvioprog at gmail.com> wrote:
>
>> when I close the server with one or more clients connected, I got a
>> memory leak.
>
>
> Check if the thread freed?
> Try to stop server manually (by button or in Close event in the form)
>
> Best Regards
> Zaher Dirkey
>

Yes, I already do it.

Now I'm trying to terminate all unterminated clients:

destructor TTcpIpServerSocketThread.Destroy;
begin
  DoTerminateClients;
  FClients.Free;
  FSocket.Free;
  inherited Destroy;
end;

....

procedure TTcpIpServerSocketThread.DoTerminateClients;
var
  VClients: TList;
  VClient: Pointer;
  VThread: TTcpIpServerClientThread;
begin
  VClients := FClients.LockList;
  try
    for VClient in VClients do
    begin
      VThread := TTcpIpServerClientThread(VClient);
      if Assigned(VThread) and not VThread.Finished then
      begin
        VThread.FreeOnTerminate := False;
        VThread.Terminate;
        FreeAndNil(VThread.FClientSocket);
        VThread.WaitFor;
        FreeAndNil(VThread);
      end;
    end;
  finally
    FClients.UnlockList;
  end;
end;

I'm testing it, on Windows it worked fine, I'll test on Linux now...

-- 
Silvio Cl├ęcio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130503/063aac55/attachment.html>


More information about the fpc-pascal mailing list