Board index » delphi » Connections of a TIdCcmTCPServer

Connections of a TIdCcmTCPServer


2008-03-26 05:50:29 PM
delphi82
what's wrong eith this code? it either blocks the app or sends an AV:
try
for i := 0 to srvProxyTCP.Contexts.LockList.Count - 1 do
ListBox1.Items.Add(TIdTCPConnection(srvProxyTCP.Contexts.LockList.Items[i]).Socket.Binding.PeerIP);
finally
srvProxyTCP.Contexts.UnlockList;
end;
 
 

Re:Connections of a TIdCcmTCPServer

I have resolved it, should be like this:
try
for i := 0 to srvProxyTCP.Contexts.LockList.Count - 1 do
ListBox1.Items.Add(TIdContext(srvProxyTCP.Contexts.LockList[i]).Connection.Socket.Binding.PeerIP);
finally
srvProxyTCP.Contexts.UnlockList;
end;
 

Re:Connections of a TIdCcmTCPServer

"Moore" <XXXX@XXXXX.COM>writes
Quote
what's wrong eith this code? it either blocks the app or sends an AV:
You are calling LockList() too many times. Every call to LockList()
requires an equal number of calls to UnlockList(), but you are not doing
that. Thus, the list remains locked after your loop finishes, blocking any
thread that tries to access the list later on. You should be calling
LockList() only once, not repeatedly.
Also, the TIdTCPServer.Contexts list holds TIdContext objects, not
TIdConnection objects. So you need to fix that as well.
Try this instead:
var
List: TList;
begin
List := srvProxyTCP.Contexts.LockList;
try
for i := 0 to List.Count - 1 do
try
ListBox1.Items.Add(TIdContext(List.Items[i]).Connection.Socket.Binding.PeerIP);
except
end;
finally
srvProxyTCP.Contexts.UnlockList;
end;
end;
Gambit
 

Re:Connections of a TIdCcmTCPServer

"Moore" <XXXX@XXXXX.COM>writes
Quote
I have resolved it, should be like this:
That code still has a fatal bug in it. See my other reply.
Gambit