Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: Indy SSL error

www.cryer.info
Managed Newsgroup Archive

Re: Indy SSL error

Subject:Re: Indy SSL error
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 10 May 2006 10:29:25

"Koger" <ingen@mail.dk> wrote in message
news:xn0em26ei39ame000@newsgroups.borland.com...

>       Socket.Connect;     //Can raise exception, when Socket.Disconnect
> called in destructor

You can't free a thread while it is still running.  You must terminate the
thread before then freeing it.  In order to make the Connect() exit as soon
as possible, you have to disconnect the socket from another thread (the main
thread in your example) so that Connect() aborts in the worker thread.

Try this code instead:

    constructor TSSLTestThread.Create;
    begin
        Socket := TIdTCPClient.Create(nil);
        Socket.IOHandler := TIdSSLIOHandlerSocket.Create(Socket);
        (Socket.IOHandler as TIdSSLIOHandlerSocket).SSLOptions.Method :=
sslvSSLv3;
        inherited Create(False);
    end;

    destructor TSSLTestThread.Destroy;
    begin
        Socket.Free;
        inherited;
    end;

    procedure TSSLTestThread.Execute;
    begin
        Socket.Host := 'www.microsoft.com';
        Socket.Port := 80;
        Socket.Connect;

        while not Terminated do
        begin
            // ...
        end;
    end;

    procedure TSSLTestThread.DoTerminate;
    begin
        Socket.Disconnect;
        inherited;
    end;

    procedure TSSLTestThread.TerminateThread;
    begin
        Terminate;
        Socket.DisconnectSocket;
        WaitFor;
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
        while True do
        begin
            with TSSLTestThread.create do
            begin
                Sleep(500);
                TerminateThread;
                Free;
            end;
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive