Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Threads communcation in network programming

Reply
Thread Tools

Threads communcation in network programming

 
 
QQ
Guest
Posts: n/a
 
      05-08-2005
Hello I am a beginner for network programming.
Now I am trying to implement some function like this

I am keep listening to a port, when I get some message, I will have
some corresponding response. And the same time, I can send out message.

So I put the listening function in the child process.
My question is when I receive some packet, how can I send signal to the
main thread.
Thanks a lot!

 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      05-08-2005

"QQ" <(E-Mail Removed)> wrote in message
>
> I am keep listening to a port, when I get some message, I will have
> some corresponding response. And the same time, I can send out message.
>
> So I put the listening function in the child process.
> My question is when I receive some packet, how can I send signal to the
> main thread.
>

You go beyond ANSI C, because there is no signalling / interrupt mechanism.
These are often provided as platform-specific calls.

However ANSI C does provide "volatile". This flags a variable as being able
to be altered by an outsode process, such as your child.

So a simple scheme would be

global variables:

struct packet data;
volatile int semaphore;

/* child */

wait till packet comes.
if semaphore not "clear" you have a problem. Maybe busy idle checking it
until it goes to "clear".
set semaphore to busy.
write data to global structure
set semaphore to "data ready"
wait till next packet comes.

/* main process */
every so often, check semaphore.
if it is set to "data ready" set semaphore to "busy", other wise go back to
main loop
read data into own structure
set semaphore to clear.
go back to main loop.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Standard Threads vs Weightless Threads yoda Python 2 08-01-2005 09:12 PM
threads without threads sindica@gmail.com C Programming 4 08-27-2004 09:25 PM



Advertisments