Jak kontrolować połączenia z serwerem INDY FTP 9 np. chciałbym zamknąć wszystkie połączenia z serwerem przed jego dezaktywacją lub kotrolować maksymalną przepustowość dla danego połączenia? Wiem, że należy użyć wątków, ale z chęcią zobaczyłbym przykładowy kod takiego rozwiązania. Na początek usatysfakcjonuje mnie uzyskanie takiej listy połączeń z serwerem, abym dostał AThread: TIdPeerThread dla każdego aktywnego połączenia z serwerem.
0
0
Dla informacji:
procedure TForm1.TerminateAllThreads;
const
LSleepTime: Integer = 250;
var
i: Integer;
LThreads: TList;
LTimedOut: Boolean;
begin
//form1.IdFTPServer1.ThreadMgr.ActiveThreads.LockList
// Threads will be nil if exception happens during start up, such as trying to bind to a port
// that is already in use.
// if Assigned(Threads) then begin
// This will provide us with posibility to call AThread.Notification in OnDisconnect event handler
// in order to access visual components. They can add notifications after the list has been
// unlocked, and before/while TerminateThreads is called
LThreads := IdFTPServer1.ThreadMgr.ActiveThreads.LockList;
try
for i := 0 to LThreads.Count - 1 do begin
with TIdPeerThread(LThreads[i]) do
Connection.DisconnectSocket;
end;
finally
IdFTPServer1.ThreadMgr.ActiveThreads.UnlockList;
end;
// Must wait for all threads to terminate, as they access the server and bindings. If this
// routine is being called from the destructor, this can cause AVs
//
// This method is used instead of:
// -Threads.WaitFor. Since they are being destroyed thread. WaitFor could AV. And Waiting for
// Handle produces different code for different OSs, and using common code has troubles
// as the handles are quite different.
// -Last thread signaling
// ThreadMgr.TerminateThreads(TerminateWaitTime);
{ 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);
end; end;
end; }
End;//TerminateAllThreads
Jest to procedura znajdująca się w klasie TIdTCPServer w sekcji
protected
co uniemożliwia skorzystanie w jej oryginalnej postaci poprzez rzutowanie. Trzeba skopiować jej zawartość do modułu głównego i dokonać kilku modyfikacji.
Pozostaje jeszcze kwestia kontrolowania przupustowości połączeń.