🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5039

Re: Indy AThread Question

#5039
From: James
Date: Mon, 25 Oct 2004 11:44
62 lines
3352 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:417aafcf$1@newsgroups.borland.com...

> What exactly are you trying to accomplish in the first place?  Please show
> an actual example.

Ok, I'm trying to allow both the OnExecute thread from TIdTCPServer, and 
another thread that I created, to have access to a client's AThread 
instance. The code below shows how I'm trying to do this, but I've taken a 
lot of stuff out (like try/catch blocks etc).

TForm1::TCPServerConnect(TIdPeerThread *AThread)
{
    CritSect->Enter();
    TClientInfo* Client = new TClientInfo();
    Client->IP = AThread->Connection->Socket->Binding->PeerIP;
    Client->Name = GStack->WSGetHostByAddr(Client->IP);
    Client->pAThread = AThread;
    // ... etc, etc.
    ListOfClients->Add(Client);
    CritSect->Leave();
}

TForm1::TCPServerExecute(TIdPeerThread *AThread)
{
    AnsiString sRaw = 
AThread->Connection->ReadLn("END",IdTimeoutInfinite,100);
    AnsiString sCmd = Decrypt(sRaw);

    // do something with sCmd here (will involve writing back to AThread
    // with AThread->Connection->Write)
}

void __fastcall ControlThread::Execute()
{
    Sleep(5000);
    CritSect->Enter();
    for (int iter = 0 ; iter != ListOfClients->Count ; iter++) {
        TClientInfo* Client = (TClientInfo*)ListOfClients->Items[iter];
        Client->pAThread->Connection->Write("Ping!");
    };
    CritSect->Leave();
}

TClientInfo is a class that holds information about each client.

In this example, ControlThread is sending "Ping!" to each client. In my 
actual program it's being used to do more than that, but I'm just showing it 
like this for simplicity.

I also realise I could use a TThreadList to store the TClientInfos instead 
of TList.

From reading previous posts, the problem is that AThread is not threadsafe, 
which means that TCPServerExecute can't sit there waiting for the string 
"END" while ControlThread::Execute is using the AThread to send "Ping!"

So how can I get these things to work together?

Thanks again for your advice and persistence,

- James 
Technical Details
Message-ID: <417ce71f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!transit.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <417256cf$1@newsgroups.borland.com> <4172b877$1@newsgroups.borland.com> <4172eeb4$1@newsgroups.borland.com> <417351b7$1@newsgroups.borland.com> <4176c89d$1@newsgroups.borland.com> <417aafcf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,67c4133e59baab76
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "James" <jb9@btinternet.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <417256cf$1@newsgroups.borland.com> <4172b877$1@newsgroups.borland.com> <4172eeb4$1@newsgroups.borland.com> <417351b7$1@newsgroups.borland.com> <4176c89d$1@newsgroups.borland.com> <417aafcf$1@newsgroups.borland.com>
Subject: Re: Indy AThread Question
Date: Mon, 25 Oct 2004 12:44:34 +0100
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 217.42.232.49
Message-ID: <417ce71f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1098704671 217.42.232.49 (25 Oct 2004 04:44:31 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!transit.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail