Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jan : TIdTCPConnection.Write freezes the current thread
| Subject: | TIdTCPConnection.Write freezes the current thread |
| Posted by: | "Adam Lister" (adam@spamless.tombola.com) |
| Date: | Thu, 5 Jan 2006 10:50:14 |
Hi,
I'm having some problems with an app that uses a TIdTCPServer component.
(V9.0.17) I *think* its something to do with a client connection
dropping but the component/application thinks its still active.
The problem occurs at random intervals (up to 24 hrs apart) and as part
of a "broadcast" where I write the same output string to each connection.
Originally I had the write command in the main thread, this resulted in
the main thread freezing completely, no exceptions or errors are thrown.
I switched it to a very inefficient approach where I create a new
thread for every client and these threads do a single write command and
then terminate. Sure enough after so long one of them freezes, more
interestingly every "broadcast" after that freezes another one, leading
me to suspect theres a faulty connection somewhere that I cant find.
Here is a the original code (the log command is threadsafe and the
freeze happens even if its not there):
with Clients.LockList do
try
for i := 0 to Count-1 do
begin
RecClient := Items[i];
RecThread := RecClient.Thread;
If (RecClient.Auth = true) and (not(RecThread.Terminated)) and
(RecThread.Connection.Connected) then
begin
try
RecThread.Connection.Write(XML + #0);
except on e: Exception do
Log('Broadcast() - Exception: ' + e.Message);
end;
end;
end;
finally
Clients.UnlockList;
end;
Any help would be greatly appreciated.
Thanks
Adam