🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Multi-threaded TCP Server with Indy 9

#2601
From: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 21:23
67 lines
2526 bytes
"Martin" <martin@styleworx.com> wrote in message
news:4412d582@newsgroups.borland.com...

> class TMyThreadClass
> {
> public:
>         TIdPeerThread*  pAThread;
>         int someparameter;
>         void __fastcall Process();
> protected:
> private:
> };

A better solution would be to derive a new class from TIdPeerThread itself
and then assign the server's ThreadClass property:

    class TMyThreadClass : public TIdPeerThread
    {
    public:
        __fastcall TMyThreadClass(bool ACreateSuspended = true);
        int someparameter;
        void __fastcall Process();
    };

    __fastcall TMyThreadClass(bool ACreateSuspended)
        : TIdPeerThread(ACreateSuspended), someparameter(1)
    {
    }

    void __fastcall TMyThreadClass::Process()
    {
        // Example
        Connection->WriteLn("Hello!");
    }

    __fastcall TForm1::TForm1(TComponent *Owner)
    {
        IdTCPServer1->ThreadClass = __classid(TMyThreadClass);
    }

    void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
    {
        TMyThreadClass* pMyThreadClass =
static_cast<TMyThreadClass*>(AThread);

        // read with AThread->Connection->CurrentReadBuffer()

        if( some conditions )
            pMyThreadClass->Process();
    }

> This code works fine. But i want to assign MyThreadClass to
> IdTCPServer->ThreadClass.

See above.

> You wrote in a previous thread, that this would be the better solution.

It is.

> But i gave it up due some access violations.

Then you probably weren't using it properly.


Gambit
Technical Details
Message-ID: <4415e291$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <441145d6$1@newsgroups.borland.com> <4411c95f$3@newsgroups.borland.com> <4412d582@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,77f2a3a304e17124
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <441145d6$1@newsgroups.borland.com> <4411c95f$3@newsgroups.borland.com> <4412d582@newsgroups.borland.com>
Subject: Re: Multi-threaded TCP Server with Indy 9
Date: Mon, 13 Mar 2006 13:23:42 -0800
Lines: 69
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4415e291$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1142284945 68.69.17.41 (13 Mar 2006 13:22:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail