Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages
Started by Boris Epel
Fri, 24 Mar 2006 07:21
how to write receiving thread correctly (Indy)
Author: Boris Epel
Date: Fri, 24 Mar 2006 07:21
Date: Fri, 24 Mar 2006 07:21
20 lines
1515 bytes
1515 bytes
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
Re: how to write receiving thread correctly (Indy)
Author: Remy Lebeau (TeamB)
Date: Fri, 24 Mar 2006 09:07
Date: Fri, 24 Mar 2006 09:07
19 lines
1711 bytes
1711 bytes
"Boris Epel" <boep777@yahoo.com> wrote in message news:44239df4$1@newsgroups.borland.com... > 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
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