(04-14-2022, 12:22 AM)kbriggs Wrote: Does Indy create additional threads beyond what it gives to each individual connection?
Yes. Each entry in the server's
Bindings collection is run in its own thread, listening for incoming connections on its assigned IP/port.
(04-14-2022, 12:22 AM)kbriggs Wrote: If so, is there any way for my app to fetch their ThreadID numbers during runtime?
The listening threads are stored in the server's
FListenerThreads member. Indy does not expose direct access to that member, however the member is declared as
protected, so you can use an accessor class to reach it, eg:
Code:
type
TIdHTTPServerAccess = class(TIdHTTPServer)
end;
var
List: TIdListenerList;
I: Integer;
begin
List := TIdHTTPServerAccess(IdHTTPServer1).FListenerThreads.LockList;
try
for I := 0 to List.Count-1 do begin
// use TIdListenerThread(List[I]).ThreadID as needed...
end;
finally
TIdHTTPServerAccess(IdHTTPServer1).FListenerThreads.UnlockList;
end;
end;
(04-14-2022, 12:22 AM)kbriggs Wrote: I ask because I'm presenting a list of active threads and what they are doing. I can of course track the ones I created myself and use the Indy OnConnect/OnDisconnect events to add/remove the connection threads to/from my list.
In that case,
TIdCustomTCPServer-based servers do have a published
OnBeforeListenerRun event that is fired when each listening thread begins running. You can get each
ThreadID from in that event. But, there is currently no corresponding
OnAfterListenerRun event available when each listening thread stops running. Though, I suppose, in the
OnBeforeListenerRun event, you could manually assign your own handler to the
TThread.OnTerminated event.