BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to write receiving thread correctly (Indy)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
Boris Epel
Guest





PostPosted: Fri Mar 24, 2006 8:03 am    Post subject: how to write receiving thread correctly (Indy) Reply with quote



Hi All,
I am writing a network application using Indy (BCB 6). I want to
transfer messages of the type {int size; ....; char *data_of_this_size}.
The receiving thread looks like this:

while(!Terminated && Client->Connected())
{
Client->ReadBuffer(block->Header, 22);
if(block->Decode(block->Header, 22)) // convert received buffer
to e.g. size
{
Client->ReadBuffer(block->Buffer, block->Size);
...;
}
}
the problem is that this code is obviously block the thread when I want
to shutdown application

Is there better way to write the receiving thread ?
Boris
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 24, 2006 10:03 am    Post subject: Re: how to write receiving thread correctly (Indy) Reply with quote



"Boris Epel" <boep777 (AT) yahoo (DOT) com> wrote in message
news:44239df4$1 (AT) newsgroups (DOT) borland.com...

Quote:
the problem is that this code is obviously block the
thread when I want to shutdown application

Simply disconnect the socket from the main thread. Any futher socket
operations on the socket will cause the reading code to throw an exception,
which will then break your while() loop so the thread can terminate.

Also, your thread code should be checking the Terminated property before
performing any lengthy operations, and before calling Synchronize() (if you
use that). Also, the main thread should call the thread's Terminate()
method before closing the socket, and then call the thread's WaitFor()
method to wait for the thread to fully terminate itself.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.