Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Closing down a Indy 9/10 IdTCPServer
| Subject: | Re: Closing down a Indy 9/10 IdTCPServer |
| Posted by: | "Matt Mazanec" (tsus..@gmail.com) |
| Date: | 21 Oct 2006 17:02:27 |
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Matt Mazanec" <tsusai@gmail.com> wrote in message
>news:4538cd0e$1@newsgroups.borland.com...
>
>> I'm looking for a proper way to do the shutdown by killing all
>> connections nicely (I have disconnection methods for the clients).
>
>TIdTCPCServer already does that for you. When setting the Active property
>to False, it disconnects all active clients, and then waits for their
>cooresponding threads to terminate themselves.
>
>> well I know I cannot do just an active := false;
>
>Yes, you can.
>
>> because all my clients time out and exceptions are raised that I cannot
>control.
>
>That is perfectly normal. Indy makes heavy use of exceptions. You will get
>an exception in your OnExecute code when the client is closed by the server.
>Just ignore it. Let the exception pass back into the TIdTCServer and it
>will be handled.
>
>> Indy 9 code (I know i got the exception wrong (this is older code as
>> i do not have fixed on hand) but I hope you understand what I am
>> getting at.
>
>You do not need any of that code in the first place.
>
>> Not sure if it works with clients that login in the meantime though....
>> thats what I am scared of.
>
>Set the server's MaxConnections property to 1 when shutting down. Or else
>disconnect the client in the OnConnect event during shutdown.
>
>> TIdPeerThread(List.Items[idx]).Connection.Disconnect;
>
>In Indy 9, use DisconnectSocket() instead of Disconnect() when closing a
>socket from another thread.
>
>
>Gambit
>
>
Ok so if I am to do just Active := false (Indy 9), how would I set it up to handle the TimeOut exception Indy will sometimes do because I have no idea.
From Indy 9 IdTCPServer.pas
if not TIdThreadSafeList(Threads).IsCountLessThan(1) then begin
LTimedOut := True;
for i := 1 to (TerminateWaitTime div LSleepTime) do begin
Sleep(LSleepTime);
if TIdThreadSafeList(Threads).IsCountLessThan(1) then begin
LTimedOut := False;
Break;
end;
end;
if LTimedOut then begin
raise EIdTerminateThreadTimeout.Create(RSTerminateThreadTimeout); <---that one.
end;
end;