🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TIdPeerThread and Syncronize...

#2785
From: Remy Lebeau (TeamB)
Date: Thu, 12 Jan 2006 19:33
109 lines
4503 bytes
"qyte" <gyte@vivodinet.gr> wrote in message
news:43c63cea$1@newsgroups.borland.com...

> TIdTcpConnection *GeneralSocket;

Why are you using a global pointer?  I do not recommend you do that.  What
exactly are you trying to accomplish?  Where does GeneralSocket get
assigned?

> [C++ Error] Unit1.cpp(2505): E2285 Could not find a
> match for 'TIdBaseThread::Synchronize(void)'

There are three workarounds for that:

1) In IdThread.hpp, comment out the second overloaded version of
Synchronize():

    HIDESBASE void __fastcall Synchronize(const Sysutils::TMethod &Method);

2) change your code to this:

    TThreadMethod m = &Client1Read;
    AThread->Synchronize(threadMethod);

3) change your code to use the TIdSync class instead of
TIdThread::Synchronize() (this option is the most portable to Indy 10):

    #include <IdSync.hpp>

    class TMethodSync : public TIdSync
    {
    private:
        TThreadMethod FMethod;
    public:
        __fastcall TMethodSync(TIdBaseThread *AThread, TThreadMethod
AMethod)
            : TIdSync(AThread), FMethod(AMethod)
        {
        }

        virtual void __fastcall DoSynchronize()
        {
            if( FMethod )
                FMethod();
        }

        static void __fastcall DoSync(TIdBaseThread *AThread, TThreadMethod
AMethod);
        {
            TMethodSync *Sync = new TMethodSync(AThread, AMethod);
            try {
                Sync->Synchronize();
            }
            __finally {
                delete Sync;
            }
        }
    };


    void __fastcall TForm1::ServerSocket1Execute(TIdPeerThread *AThread)
    {
        //...
        TMethodSync::DoSync(AThread, Client1Read);
        //...
    }


> I am using BCB6 and indy 9.0.14.

9.0.14 is a very old build.  The current Development Snapshot build is
9.0.50.

> Apart from that i seem to have another problem.

You should have posted a new discussion thread for that.

> ReadFromStack does not return if there are data left
> in the socket which i have not already read.

Yes, it does.  That is exactly what ReadFromStack() is specifically designed
to do - read unread data from the socket.

> I mean that the program seems to work if i just call the read
> methods instead of using ReadFromStack before them.

Under most circumstances, you don't need to call ReadFromStack() at all.
The only time you should be calling it directly is when you don't know ahead
of time how much data you want to read, so you just read everything that is
currently available.

> I saw another thread that did the following

Are you saying that ReadFromStack() does not return if there is data
available in the InputBuffer?  If so, then it is doing what it is supposed
to be doing.  ReadFromStack() is what puts incoming data into the
InputBuffer in the first place.  ReadFromStack() ignores the existing
contents of the InputBuffer because it deals only with the underlying socket
directly.  If there is data available on the socket, the data is removed
from the socket and put into the InputBuffer.  All other reading methods in
Indy use only the InputBuffer, never the socket directly.  If the
InputBuffer does not contain enough bytes, ReadFromStack() is called
automatically to put more bytes into the InputBuffer.  If no bytes are
available in the socket when ReadFromStack() is called, it blocks until
bytes actually arrive, or until the specified timeout elapses.


Gambit
Technical Details
Message-ID: <43c6ae83$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43c5b81c$1@newsgroups.borland.com> <43c5d928$1@newsgroups.borland.com> <43c63cea$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,7a3f39d19ff01203
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: <43c5b81c$1@newsgroups.borland.com> <43c5d928$1@newsgroups.borland.com> <43c63cea$1@newsgroups.borland.com>
Subject: Re: TIdPeerThread and Syncronize...
Date: Thu, 12 Jan 2006 11:33:49 -0800
Lines: 111
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: <43c6ae83$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1137094275 68.69.17.41 (12 Jan 2006 11:31:15 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail