Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by qyte
Thu, 12 Jan 2006 02:02
TIdPeerThread and Syncronize...
Author: qyte
Date: Thu, 12 Jan 2006 02:02
Date: Thu, 12 Jan 2006 02:02
16 lines
1329 bytes
1329 bytes
I use the following code inside the OnExecute event of the server. AThread->Synchronize(ClientRead); But it throws a compiler error. What am i doing wrong? Just to tell that ClientRead is declared inside the published part of TFrmMain as void __fastcall ClientRead(void); and the problem is that it can be called from inside the OnExecute of a TThread Descendant that i have created as Synchronize(FrmMain->ClientRead). Why is this happening???
Re: TIdPeerThread and Syncronize...
Author: Remy Lebeau (TeamB)
Date: Thu, 12 Jan 2006 04:16
Date: Thu, 12 Jan 2006 04:16
13 lines
1324 bytes
1324 bytes
"qyte" <gyte@vivodinet.gr> wrote in message news:43c5b81c$1@newsgroups.borland.com... > AThread->Synchronize(ClientRead); > > But it throws a compiler error. Please be more specific. What is the exact error message? And which version of BCB are you using? Gambit
Re: TIdPeerThread and Syncronize...
Author: qyte
Date: Thu, 12 Jan 2006 11:29
Date: Thu, 12 Jan 2006 11:29
45 lines
2319 bytes
2319 bytes
Remy Lebeau (TeamB) wrote:
> "qyte" <gyte@vivodinet.gr> wrote in message
> news:43c5b81c$1@newsgroups.borland.com...
>
>> AThread->Synchronize(ClientRead);
>>
>> But it throws a compiler error.
>
> Please be more specific. What is the exact error message? And which
> version of BCB are you using?
>
>
> Gambit
>
>
TIdTcpConnection *GeneralSocket;
void __fastcall TForm1::ServerSocket1Execute(TIdPeerThread *AThread)
{
int BytesGet=AThread->Connection->ReadFromStack(false,1000,false);
if(BytesGet>0)
{
if(AThread->Connection==GeneralSocket)
AThread->Synchronize(Client1Read);
}
}
[C++ Error] Unit1.cpp(2505): E2285 Could not find a match for
'TIdBaseThread::Synchronize(void)'
I am using BCB6 and indy 9.0.14.
Apart from that i seem to have another problem.
ReadFromStack does not return if there are data left
in the socket which i have not already read.
I mean that the program seems to work if i just
call the read methods instead of using ReadFromStack before
them. Is there a way avoiding that?
I saw another thread that did the following
int
Bytes=Connection->InputBuffer->Size==0?ReadFromStack(false,1000,false):Connection->InputBuffer->Size;
Is that better?
Re: TIdPeerThread and Syncronize...
Author: Remy Lebeau (TeamB)
Date: Thu, 12 Jan 2006 19:33
Date: Thu, 12 Jan 2006 19:33
109 lines
4503 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads