Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Jan : Indy TIdTCPClient with addition read thread

www.cryer.info
Managed Newsgroup Archive

Indy TIdTCPClient with addition read thread

Subject:Indy TIdTCPClient with addition read thread
Posted by:"Gaspar" (norep..@noreply.com)
Date:Sat, 6 Jan 2007 18:57:37

I have a TIdTCPClient that sends commands to a TIdCmdTCPServer.
I have an additional thread that reads messages from server. It is protected
with a CriticalSection so as to not interfere with SendCmd's results.

Basically I do...
   while not Terminated and Data.Client.IOHandler.Connected do
   begin
      // Enter critical section
      ...
      // Check if something to read
      line := Data.Client.IOHandler.ReadLn(LF, SOME_TIMEOUT);
      // Leave critical section
      ...
    end

There are two problems with this implementation:
1) The thread is busy-waiting.
2) SOME_TIMEOUT should be as small as possible to leave the critical section
as soon as possible.

My questions are:
1) Is there anyway to use an INFINITE_TIMEOUT (to avoid busy-waiting) and
"wake-up" the IOHandler from it's readln operation when the section is
needed?
2) If not, what about using a very very small timeout (say 100 ms) and then
sleeping some seconds outside the critical section?

Thanks for your help!

Replies:

www.cryer.info
Managed Newsgroup Archive